I'm writing a inline function in AS3 as a Event handler for a Loader class, the issue I having is that in this inline function it needs to access variables outside the scope of the function.
Here's the code I running:
for(var i:uint=0;i<numChildren;i++){;
var displayObj:DisplayObject = getChildAt(i);
var displayObjWidth = displayObj.width;
if (elementname == displayObj.name)
{
var loader:Loader = new Loader();
var urlRequest:URLRequest = new URLRequest(loadURL);
loader.load( urlRequest );
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){
var mw:Number = displayObj.width;
var mh:Number = displayObj.height;
var tempImage:Bitmap = new Bitmap(e.target.content.bitmapData);
image.bitmapData = tempImage.bitmapData;
image.width = mw;
image.height = mh;
loader.width = displayObj.width;
loader.height = displayObj.height;});
loader.x = displayObj.x;
loader.y = displayObj.y;
addChild( loader );
removeChild( displayObj );
}
This function is loading a image from a URL, then finding a match child element and replacing the existing image with the new one that has loaded.
The problem I'm having is getting is being able to access the height and width of the original display object I am replacing with the new one loaded via the Loader class.
How can I access these variables outside the scope of the function or pass them to the function?