flash on 2010-4-16

by yd_niku
♥0 | Line 51 | Modified 2010-04-16 11:53:04 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            if( stage ) init(null);
            else addEventListener(Event.ADDED_TO_STAGE,init);
        }
        private var _views:Array = [];
        private var _particles:Vector.<Particle> = new Vector.<Particle>();
        public function init(e:Event):void{
            removeEventListener(Event.ADDED_TO_STAGE,init);
            
            _particles.push(
                new Particle( 50,300),
                new Particle(200,300),
                new Particle(350,300)
            );
            
            for each( var p:Particle in _particle ) {
                _views.push( new Ball(p) );
            }
        }
    }
}

import flash.display.*;
class Ball extends Sprite{
    private var data:Particle;
    public function Ball(p:Particle){
        data = p;
        graphics.beginFill(0x6666ff);
        graphics.drawCircle(0,0,20);
        graphics.endFill();
    }
    public function update():void{
        x = data.x;
        y = data.y;
    }
}

class Particle {
    public var x:Number;
    public var y:Number;
    
    public var vx:Number;
    public var vy:Number;
    
    public var life:int = 100;
    public function Particle(sx:Number=0, sy:Number=0, svx:Number=0, svy:Number=0){
        x = sx;
        y = sy;
        vx = svx;
        vy = svy;
    }
}