This content has been marked as final. Show 3 replies
I don't see anything obviously "wrong" with what you are doing; the Complete event shouldn't be dispatched until the data has been loaded. I don't see where you are making the actual load request.
However, I wouldn't use this technique to load XML data; there are easier ways. I would use HTTPService with resultFormat="e4x". The HTTPService's result event will be fired when the data has completely loaded. You can either do this in MXML or in ActionScript.
"...use HTTPService with resultFormat="e4x..." I agree completely. Though you are close to this in what you have and URLLoader is very similar to HTTPService, HTTPService is designed spedifically for this usage and is a bit easier to use.
Like Peter says, what you have should not have any issues with network timing, and switching to HTTPService won't change the behavior, though.
How are you determining that you are having a problem? Have you done a trace() in the result handler to verify your data? trace(this.xmlDoc.toXMLString()). Use toXMLString() ALWAYS with xml.
I was getting null object references because my complex object was responsible for loading the xml data and exposing the data as properties and other objects within faster than the XML data could load. My way of thinking, I guess was that it was logical for a configuration object as I've had it to be responsible for loading its own configuration file. I've separated this out so that the main MXML app loads the configuration XML data using the HTTPService and then fires off the creation of the object and no problems now (fingers and toes crossed).
But even then, what would I have had to do to get an object that is its own data loader to do in order to fire off an event that it was done doing the loading of the data and have it 'trickle' up to the main application to signal that it was done? The whole event system is easy to understand when someone else has written the code for it, but when it comes to doing it on my own I need way more practice, it seems :-)