I have small problem. I’m dynamically loading JPG file using Loader class. Everything works except if I want to tile the image few more times using addChild(loader.content) it just doesn’t work. It always removes previous instance and leaves only the last one. I’ve tried everything but with no luck. Here’s my code:
var loaderContext:LoaderContext = new LoaderContext(true);
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaderDone);
var fileRequest:URLRequest = new URLRequest('http://127.0.0.1/blah/blah.jpg');
imageLoader.load(fileRequest, loaderContext);
var imageLoaderDone:Function = function(e){
var k:int = landHolder.numChildren;
while(k--) {
landHolder.removeChildAt(k);
}
var howManyTimes:int = Math.ceil(1000 / e.content.width);
var i:int = 0;
while(i < howManyTimes) {
var zombie:Sprite = new Sprite();
zombie.addChild(e.content);
zombie.x = i*zombie.width;
landHolder.addChild(zombie); //here's the problem, it does not duplicate
//landHolder is empty MovieClip placed on the stage
i++;
}
landHolder.alpha = 1
}
Thanks.
In case of a loaded image, you could simply clone its bitmap data.
The other suggested solutions are good alternatives when you need to clone more than a simple image.