I have an arbitrary number of files that I need to load in an AIR app.
I want to iterate through an array of File object and create and launch Loaders for each one's File.url.
When they are done (event COMPLETED or IOErrorEvent.IO_ERROR), I want to stuff their data somewhere. If they fail, I want to make an exception report. I cannot find any way to reference the File object from the event listener (certainly not the IO_ERROR)
The best way would be to create individual event handlers for each Launcher that had the File information "hard-coded" into it. At the very least, I could use the function itself as an index to a Dictionary:
foo(fileToLoad : File) : void
{
var theCompletedHandler : Function =
{
var theFile : File = completedHandlerLookup[?????? this function ?????];
var theData : ImageData =
new ImageData(theFile.url, (_loader.content as Bitmap).bitmapData);
// do something with the data
delete completedHandlerLookup[?????? this function ?????];
delete errorHandlerLookup.findByValue(theFile); // [sic]
}
var theErrorHandler : Function =
{
var theFile : File = errorHandlerLookup[?????? this function ?????];
// report the error
delete errorHandlerLookup[?????? this function ?????];
delete completedHandlerLookup.findByValue(theFile); // [sic]
}
completedHandlerLookup[theCompletedHandler] = theCompletedHandler;
errorHandlerLookup[theCompletedHandler] = theErrorHandler;
var theLoader : Loader = new Loader();
theLoader.addEventListener(Event.COMPLETE, theCompletedHandler);
theLoader.addEventListener(IOErrorEvent.IO_ERROR, theErrorHandler);
theLoader.load(new URLRequest(fileToLoad.url));
Can I use event.currentTaget and use the Loader instance as an index? Will that have any weird dependencies ?
Cheers