flash on 2011-4-22

by e_2o
♥0 | Line 41 | Modified 2011-04-22 23:53:00 | MIT License
play

ActionScript3 source code

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

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 = 110;
            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;
    }
}