flash on 2011-5-20

by hacker_aft9cz2z
♥0 | Line 58 | Modified 2011-05-20 21:06:20 | MIT License
play

ActionScript3 source code

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

package 
{
    import flash.geom.Rectangle;
    import flash.display.*;
    import flash.events.*;
    
    
    public class Star extends Sprite 
    {
        public function Star() 
        {
            // write as3 code here..
            
            init();
        }
        
        
        private const NUM:int = 100;
        
        private var _list:Array;
        private var _sp:Sprite;
        private var _bmpd:BitmapData;
        private var _bmp:Bitmap;
        
        
        private function init():void
        {
            _list = [];
            _sp = new Sprite();
            _bmpd = new BitmapData(500, 500, true, 0x00FFFFFF);
            
            this.graphics.beginFill(0x000000);
            this.graphics.drawRect(0,0,500,500);
            this.graphics.endFill();
            
            for(var i:int=0; i < NUM; i++)
            {
                var p:Shape = new Shape();
                p.graphics.beginFill(0xFFFFFF);
                p.graphics.drawCircle(0,0,1);
                p.graphics.endFill();
                
                p.x = Math.random()*500;
                p.y = Math.random()*500;
                
                p.scaleX = p.scaleY = Math.random();
                
                _sp.addChild(p);
                _list.push(p);
            }
            
            _bmpd.draw(_sp);
            _bmp = new Bitmap(_bmpd);
            
            this.addChild(_bmp);
            
            addEventListener(Event.EXIT_FRAME, update);
        }
        
        
        private function update(e:Event):void
        {
            for(var i:int=0; i < _list.length; i++)
            {
                var p:Shape=_list[i];
                p.x -= p.scaleX;
                
                if(p.x < 0)
                {
                    p.x = 500 + Math.random()*500;
                    p.y = Math.random()*500;
                }
            }
            
            _bmpd.fillRect(new Rectangle(0,0,500,500), 0x00FFFFFF);
            _bmpd.draw(_sp);
        }
    }
}