flash on 2010-4-14

by kihon
♥0 | Line 41 | Modified 2010-04-14 00:12:06 | MIT License
play

ActionScript3 source code

/**
 * Copyright kihon ( http://wonderfl.net/user/kihon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iP96
 */

package
{
	import flash.display.Sprite;
	import flash.events.Event;
 
	public class Main extends Sprite
	{
		private var ball:Ball;
 
		public function Main()
		{
			ball = new Ball();
			ball.x = 100;
			ball.y = 200;
			addChild(ball);
 
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function onEnterFrame(event:Event):void
		{
			ball.move();
		}
	}
}
 
import flash.display.Sprite;
 
class Ball extends Sprite
{
	public const RADIUS:int = 30;
	public var vx:int = 10;
	public var vy:int = 10;
 
	public function Ball()
	{
		graphics.beginFill(0x0);
		graphics.drawCircle(0, 0, RADIUS);
		graphics.endFill();
	}
 
	public function move():void
	{
		this.x += vx;
		this.y += vy;
 
		if (this.x - RADIUS < 0 || stage.stageWidth  <= this.x + RADIUS) vx = -vx;
		if (this.y - RADIUS < 0 || stage.stageHeight <= this.y + RADIUS) vy = -vy;
	}
}