I’m developing a flash application that is getting information from a remote server using a URLLoader. I have a function that will create a request for information based on the product ID. When there is an error, I want to fall back to an alternate URL, but to create the alternate URL, I need to know the product ID. What is the best method to determine which URLLoader failed (and which product request failed) so that I can regenerate the new URL?
My functions are below:
function loadData(productID:String):URLLoader {
var productURL:URLRequest = new URLRequest("/path/to/product/" + productID);
var dataLoader:URLLoader = new URLLoader();
dataLoader.addEventListener(Event.COMPLETE, parseData);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, handleDataError);
dataLoader.load(productURL);
return dataLoader;
}
function handleDataError(e:IOErrorEvent) {
var productID:String = ???;
var altProductURL:URLRequest = new URLRequest("/alternate/path/to/product/" + productID);
var dataLoader:URLLoader = new URLLoader();
dataLoader.load(altProductURL);
}
You could wrap your error handler in a local variable (which describes a new function) so you can pass the ID to the method which receives the error event: