URLLoader - No Error Event, No Success Event
All,
I have encountered an interesting problem when I try to load an .xml file using a URLLoader (within my own custom class). I have several configuration .xml files which I use to configure the application when it launches.
For example, in the code below, myCustomLoader is a custom class I wrote that takes an .xml file as a parameter. The myCustomLoader class encapsulates all the instantiation of the URLLoader class and error handling etc. The code below operates as expected, the configuration files load into memory, and they're accessible throughout my App.
Actionscript Code:
// On launch
var Config1:XML = new myCustomLoader("Config1.xml");
var Config2:XML = new myCustomLoader("Config2.xml");
var Config3:XML = new myCustomLoader("Config3.xml");
I've developed a situation where I need to load some "2nd level" .xml files. For example, a .xml file full of images for a gallery display.
However, as the user interacts with the app and objects are added and removed and the state of the application changes, sometimes these "2nd level" .xml files load successfully, and sometimes they don't load or fail at all.
By that I mean I LITERALLY get no notification or hint from Flash about what is wrong. There is no compile or runtime error, but there is no "complete" event either. The App doesn't stop working, the .xml just doesn't load. In fact, it seems that .xml doesn't even open.
In myCustomLoader I have listeners for EVERY event that the URLLoader dispatches, with trace statements that would tell me what was wrong. For example:
Actionscript Code:
// From some other class
var anotherXML:XML = new myCustomLoader("2ndlevel1.xml");
// myCustomLoader class
package {
public class myCustomLoader extends EventDispatcher {
public function myCustomLoader(filePath:String) {
var urlLoader:URLLoader = new URLLoader("2ndlevel1.xml");
urlLoader.addEventListener(Event.OPEN, onOpen, false, 0, true);
urlLoader.addEventListener(ProgressEvent.PROGRESS, onProgress, false, 0, true);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus, false, 0, true);
urlLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError, false, 0, true);
// Try loading the text
try {
urlLoader.load(new URLRequest(filePath));
} catch (errLoad:Error) {
trace("Unable to load content : " + errLoad.message);
}
}
// ...
// trace errors or success, etc.
// return an XML object
}
}
The load() in the "try" block successfully executes, but the "open" event never triggers. I'm assuming the problem lies in the application state and code outside of the loader class since it seems to work fine in other situations.
Unfortunately, I'm working with someone else's "legacy" code, so I have no idea where the problem could be, so I wouldn't even know what code to post here and ask for proof-reading.
So, I'm hopping someone might be able to give me a "code-agnostic" reason why a URLLoader.load() call would not fail, but no events would dispatch and no data would be loaded?
Thanks!