In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

particle

Get Adobe Flash player
by SoWhat1983 10 Dec 2009
    Embed
/**
 * Copyright SoWhat1983 ( http://wonderfl.net/user/SoWhat1983 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8MZS
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.utils.Timer;
    import flash.geom.*;
    import net.hires.debug.Stats;
    
    [SWF(backgroundColor=0x0)]
    public class ParticleDemo extends Sprite {
        
        public var emitterX:Number = stage.stageWidth/2;
        public var emitterY:Number = stage.stageHeight/2;
        
        public function ParticleDemo() {
            
            // stats
            addChild(new Stats());
            
            var ttt:Timer = new Timer(10);
            ttt.addEventListener(TimerEvent.TIMER,onLoop);
            ttt.start(); 
            //stage.addEventListener(Event.ENTER_FRAME, onLoop, false,0,true);
        }
        
        private function onLoop(evt:Event):void{
            var p:Particle = new Particle(
                mouseX,
                mouseY,
                Math.random()*11-6,
                Math.random()*-20,
                1,
                Math.random() * 0xFFFFFF
            );
            addChild(p);
        }
    }
}


import flash.display.Sprite;
import flash.geom.*;
import flash.events.Event;

class Particle extends Sprite {
    private var _xpos:Number;
    private var _ypos:Number;
    private var _xvel:Number;
    private var _yvel:Number;
    private var _grav:Number;
    private var _mtrx:Matrix;
    private var _scaleD:Number = 1;
    
    public function Particle (xp:Number,yp:Number,xvel:Number,yvel:Number,grav:Number,col:uint) {
        _xpos = xp;
        _ypos = yp;
        _xvel = xvel;
        _yvel = yvel;
        _grav = grav;
        
        var ball:Sprite =new Sprite();
        with(ball.graphics) {
            beginFill(0xff0000);
            drawCircle(0,0,10);
        }
        addChild(ball)
        
        x = _xpos;
        y = _ypos;
        alpha =0.8;
        scaleX =scaleY = Math.random() * 1.6+ 0.4;
         
        var colorInfo:ColorTransform = ball.transform.colorTransform;
        colorInfo.color = col;
        ball.transform.colorTransform = colorInfo;
        
        
        // scaleX = 0.5; 
        // _mtrx.rotate(Math.random());
        
        
        addEventListener(Event.ENTER_FRAME, onRun,false,0,true);
    }
    
    private function onRun(evt:Event):void {
        _yvel += _grav;
        _xpos += _xvel;
        _ypos += _yvel;
        
        
        if (_xpos < 0 || _xpos > stage.stageWidth || _ypos > stage.stageHeight ) {
            removeEventListener(Event.ENTER_FRAME,onRun);
            parent.removeChild(this);
        }
        
        x =_xpos;
        y =_ypos;
    }
}