How to Clone Loader
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9xA0
*/
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 w:int = Math.ceil(stage.stageWidth / bitmapData.width);
var h:int = Math.ceil(stage.stageHeight / bitmapData.height);
var i:int, j:int;
var bm:Bitmap;
for (i = 0; i < w; i ++) {
for (j = 0; j < h; j++) {
bm = new Bitmap(bitmapData.clone());
bm.x = bitmapData.width * i;
bm.y = bitmapData.height * j;
addChild(bm);
}
}
}
}
}