views:

40

answers:

1

I'm trying to load external SWFs in a for loop, and I have this problem that is really eating me: In the event handler I need to know the filename of the SWF that was loaded, but I can't obtain this. The code below shows what I'm trying to do.

Does anybody have any idea?

function loadManySWFs(arrayOfFileNames:Array)
{
    for(var i=0; i<arrayOfFileNames; i++)
    {
        var mLoader:Loader = new Loader();
        var mRequest:URLRequest = new URLRequest(arrayOfFileNames[i]));
        mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        mLoader.load(mRequest);
    }

}


function onLoadComplete(e:Event)
{
    // Here I need to know the filename of the SWF that was loaded. How can I do this?

}

Thanks for any help!

+3  A: 

event.target would contain the relevant LoaderInfo object, you can retrieve the url from that.

function onLoadComplete(e:Event):void {
    trace(LoaderInfo(e.target).url);
}
maxmc
@maxmc `event.target` would be the `LoaderInfo` object with which the event listener was registered. Edited to fix it.
Amarghosh
@Amarghosh: thanks
maxmc