R – AS3: Loading SWFs in a for loop

actionscript-3closuresevent handlingflash

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!

Best Answer

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);
}
Related Topic