flash on 2014-12-24

by hemingway
♥0 | Line 38 | Modified 2015-01-07 03:49:31 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    public class SNOW extends Sprite {
        private var _canvasData:BitmapData;
        private var _canvas:Bitmap;
        private var _snow:Vector.<Vector.<int>>;
        private var _frame:int;
        
        public function SNOW() {
            this._canvasData = new BitmapData(465, 465, false, 0);
            this._canvas = new Bitmap(this._canvasData);
            this._snow = new Vector.<Vector.<int>>;
            this._snow.push(new <int> [232, 1]);
            this._frame = 0;
            
            this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
        }
        
        private function addedToStageHandler($event:Event):void {
            this.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
            
            this.addChild(this._canvas);
            
            this.addEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
        }
        
        private function enterFrameHandler($event:Event):void {
            this._frame++;
            
            for (var $:int; $<this._snow.length; $++) {
                if ((this._snow[$][1] + 1) < 464) {
                    this._snow[$][1]++;
                    this._snow[$][0]+=(Math.random()*3)-1;
                    this._canvasData.setPixel(this._snow[$][0], this._snow[$][1], 0xFFFFFF);
                } else {
                    this._snow[$][1]
                }
            }
        }
    }
}