blue ball

by wexler
♥0 | Line 36 | Modified 2011-01-02 01:46:49 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.*; 
    [SWF(width = "200", height = "200", frameRate = "60", backgroundColor = "#FFFFFF")]

    public class FlashTest extends Sprite {
        private var _pos:Point = new Point(100, 10);
        private var _vel:Point = new Point(2, 0);
        private var _radius:int = 5;
        public function FlashTest() {
            addEventListener(Event.ENTER_FRAME,update); 
        }
              
        public function update(e:Event):void
        {
            _vel.y += 1;
            _pos.x += _vel.x;
            _pos.y += _vel.y;
            
            if( _pos.x < 0 + _radius ) {
                _pos.x = 0 + _radius;
                _vel.x *= -1;
            }
            if( _pos.x > 200 - _radius ) {
                _pos.x = 200 - _radius;
                _vel.x *= -1;
            }
            if( _pos.y > 200 - _radius) {
                _pos.y = 200 - _radius;
                _vel.y *= -1;
            }
             
            graphics.clear();
            graphics.beginFill(0x0000FF);
            graphics.drawCircle(_pos.x, _pos.y, _radius);
            graphics.endFill();
        }
    }
}

Forked