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

forked from: タイル状にローディング

// forked from abakane's タイル状にローディング
package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import caurina.transitions.Tweener;
    
    public class LoadingPanel extends Sprite{
        public var loader:Loader;
        public var p:uint = 0;
        public var total:uint;
        public var current:uint = 0;
        public var panelAry:Array = [];
        public var side:Number = 50;
        public var col:uint;
        
        public function LoadingPanel(){
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, onProgress);
            loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete);
            loader.contentLoaderInfo.addEventListener( Event.OPEN, onOpen);
            loader.load( new URLRequest( "http://farm2.static.flickr.com/1250/567791491_5855bf986d_b.jpg" ) );
        }
        
        private function onOpen( e:Event ):void{
            col = Math.ceil( stage.stageWidth/side );
            total = col*Math.ceil(stage.stageHeight/side);
            this.addEventListener( Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onProgress( e:ProgressEvent ):void{
            current = Math.round(e.bytesLoaded/e.bytesTotal*total);
        }
        
        private function onComplete( e:Event ):void{
            loader.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, onProgress);
            loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, onComplete);
            loader.contentLoaderInfo.removeEventListener( Event.OPEN, onOpen);
        }
        
        private function onEnterFrame( e:Event ):void{
            if( p < current ){
                var panel:Sprite = new Sprite();
                panel.alpha = 0;
                panel.x = Math.random()*stage.stageWidth;
                panel.y = Math.random()*stage.stageHeight;
                panel.scaleX = panel.scaleY = 0;
                panel.name = String(p);
                panel.graphics.beginFill( 0x000000, 1);
                panel.graphics.drawRect( 0, 0, side, side);
                panel.graphics.endFill();
                panelAry.push( panel );
                addChild( panel );
                Tweener.addTween( panel, {alpha:1, x:p%col*side, y:Math.floor(p/col)*side, scaleX:1, scaleY:1, time:0.8, transition:"easeOutExpo", onComplete:function():void{ if(Number(this.name) >= total-1){ end();} } } );
                p ++;
            }
        }
        
        private function end():void{
        	this.removeEventListener( Event.ENTER_FRAME, onEnterFrame);
          for(var i:uint=0; i<panelAry.length; i++){
          	Tweener.addTween( panelAry[i], {alpha:0, time:0.4, delay:Math.random()*0.5, onComplete:function():void{ removeChild(this); } } );
          }
        	var r:Number = stage.stageWidth/loader.width >= stage.stageHeight/loader.height ? stage.stageWidth/loader.width : stage.stageHeight/loader.height;
        	loader.scaleX = loader.scaleY = r;
        	addChildAt( loader, 0);
        }
        
    }
}