Reusing image from loader - how to duplicate image into a sprite
Hello.
I'd like to be able to load an external image and then use the loaded image multiple times within a sprite.
So, from what I can make out, I need to get the image out of the Loader somehow and use it as a Bitmap.
Have been looking for a solution for this for hours now, and attempting every possible permutation I could think of, but have hit a real dead end.
Am really hoping someone can point me in the right direction.
Here's my code:
import flash.display.Bitmap;
var sp:Sprite = new Sprite();
addChild(sp);
var bitmapData:BitmapData;
var imageURLRequest:URLRequest = new URLRequest("images/myimage.png");
var loader:Loader = new Loader();
loader.load(imageURLRequest);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function imageLoaded(e:Event):void {
bitmapData = e.target.content.bitmapData;
var myBitmap:Bitmap = new Bitmap;
myBitmap.bitmapData = bitmapData;
for (var i:int=1; i<3; i++) {
myBitmap.x = 300* (i-1);
sp.addChild(myBitmap);
}
}
Any ideas how I can fix this so that the loaded image outputs 3 times in the sprite?
Many thanks.