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

Snow 2.0

Wanted to imporve upon it with fewer lines of code... Still working on it. Planning to add a few more features.
Get Adobe Flash player
by neofatalist 26 Dec 2011

    Tags

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

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.utils.Timer;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import net.hires.debug.Stats;
       
    [SWF(backgroundColor=0x000000, width = '465', height = '465', frameRate = '100')]
    public class Main extends Sprite {
        internal var emitTime:int = 1;
        internal var emitter:Timer = new Timer(emitTime);   
        //internal var flakes:Array;
        internal var stats:Stats = new Stats();
        internal var snowLayer:Sprite;
             
        public function Main() {                
            addChild(new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x660000)));    // why doest the background color work? oh well.    
            addEventListener(Event.ADDED_TO_STAGE, init);
            addEventListener(Event.REMOVED_FROM_STAGE, dispose)
        }
        
        internal function init(e:Event):void{
            removeEventListener(Event.ADDED_TO_STAGE, init);
            emitter.start();
            emitter.addEventListener(TimerEvent.TIMER, emit)
            
            snowLayer = new Sprite();
            addChild(snowLayer)
            stage.addChild( stats );
        }
        
        internal function emit(e:TimerEvent):void{
            if(snowLayer.numChildren-1 < 300){
                snowLayer.addChild(Sprite(new particle(
                    -100 + Math.floor(Math.random()*1000),
                    (Math.random()*900)+550,
                    -700
                )));
            }
        }       
       
        internal function dispose(e:Event):void{
            removeEventListener(Event.REMOVED_FROM_STAGE, dispose)
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
import flash.filters.*;
import flash.geom.Matrix;
import flash.display.GradientType;

 class particle extends Sprite{
    internal var rect:Sprite = new Sprite();
    internal var onStage:Boolean = false;        
    internal var xVel:Number = (Math.random()*2)-1;
    internal var yVel:Number= 2.5;
    internal var zVel:Number = Math.random()*5 - 2.6;
    internal var fil:BlurFilter = new BlurFilter();
    internal var _id:Number;

    public function particle(xx:Number, zz:Number, yy:Number) {
        x = xx;
        z = zz;
        y = yy;
        addEventListener(Event.ADDED_TO_STAGE, added);
        addEventListener(Event.REMOVED_FROM_STAGE, dispose);            
    }
        
    internal function added(e:Event):void{
        var mat:Matrix= new Matrix();
        var colors:Array = [0xEEEEEE,0xFFFFFF];
        var alphas:Array = [1,0];
        var circRad:Number = 10;
        var ratios:Array = [0,255];            

        mat.createGradientBox(2*circRad, 2*circRad, 0, -circRad, -circRad);
        graphics.lineStyle();
        graphics.beginGradientFill(GradientType.RADIAL,colors,alphas,ratios,mat);
        graphics.drawCircle(0,0,circRad);
        graphics.endFill();
            
        addEventListener(Event.ENTER_FRAME, loop)
        onStage=true;
        cacheAsBitmap = true;
    }
        
    internal function loop(e:Event):void{
        if(y < 650){
            y+=(yVel +(z/900));
            x+=xVel;
            z+=zVel;
                                
            yVel+= .01;
            xVel += (Math.random()*1)-.5;
            zVel += (Math.random()*1) - .5;
            if( y < -800 || x < -500 || x > 1800 || z > 2000 || z < -2000 ){Sprite(parent).removeChild(this)};
        }else{
            alpha  -= .02;
            if(scaleX < 2) scaleX += .04;
            if(scaleY > .25)scaleY -= .02;                
            if(alpha < 0) {Sprite(parent).removeChild(this)};
        }   
    }        
        
    internal function dispose(e:Event):void{
            fil = null;
            onStage=false;
            removeEventListener(Event.ENTER_FRAME, loop)
            removeEventListener(Event.ADDED_TO_STAGE, added);
            removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
    }
}