flash on 2009-6-8

by zsp
♥0 | Line 42 | Modified 2009-06-11 21:33:29 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    [SWF(width="400",height="400",frameRate = "30")]
    public class FlashTest extends Sprite {
        
        private var ball: Ball;
        private var balls:Vector.<Ball>;

        private const BL_NUM: Number = 40;

        public function FlashTest() {
            balls = new Vector.<Ball>;

            for (var i:int = 0; i<BL_NUM; i++){
                var b: Ball  = new Ball(Math.random()*400,Math.random()*400);
                balls.push(b);
                addChild(b);
            }

            addEventListener(Event.ENTER_FRAME, update);
            
        }

        public function update(e:Event):void{
            for(var i:int = 0; i<BL_NUM; i++){
                balls[i].move();
            }
        }
    }
}

    import flash.display.Sprite;
    class Ball extends Sprite{
        private var vx: Number = Math.random()*10-5;
        private var vy: Number = Math.random()*10-5;//20;
        public function Ball(tx:int, ty:int){
            graphics.beginFill(0x00FF00);
            graphics.drawCircle(0,0,10);    
            graphics.endFill();

            x= tx;
            y= ty;
        }
        public function move():void{
            x += vx;
            y += vy;

            if((x<0)||(400<x)) vx = -vx;
            if((y<0) ||(400<y)) vy = -vy;
        }
    }