forked from: How to Clone Loader

by hacker_9p8x8mco forked from How to Clone Loader (diff: 16)
♥0 | Line 38 | Modified 2010-01-08 23:31:19 | MIT License | (replaced)
play

ActionScript3 source code

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

// forked from 9re's How to Clone Loader
package {
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.system.LoaderContext;
	import flash.net.URLRequest;
	import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.system.ApplicationDomain;
    import flash.system.SecurityDomain;
    
    public class FlashTest extends Sprite {
    		private var IMG:String = 'http://assets.wonderfl.net/images/related_images/7/73/7377/73775e5afa10f14aa6479cfcff925f7763b98384';
    		private var bitmapData:BitmapData;
    		
        public function FlashTest() {
            // write as3 code here..
            var ldr:Loader = new Loader;
            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
            ldr.load(new URLRequest(IMG), new LoaderContext(true));
            
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.addEventListener(Event.RESIZE, bitmapFill);
            stage.dispatchEvent(new Event(Event.RESIZE));
        }
        
        private function onImageLoaded(e:Event):void {
        		// the Bitmap of the image loaded is set as loader.content
        		bitmapData = Bitmap(e.target.loader.content).bitmapData;
        		bitmapFill(null);
        }
        
        private function bitmapFill(e:Event):void {
       		if (bitmapData == null) return;
       	
      		
       		var bm:Bitmap;
       		bm = new Bitmap(bitmapData);
       		bm.x = stage.stageWidth / 2;
       		bm.y = stage.stageHeight / 2;
			addChild(bm);
        }
    }
}