View Full Version : How to know external data is loaded completely
adarsh123
June 16th, 2009, 08:00 AM
Hello,
Here i'm facing one problem while reading an external xml file..my execution is going on before file loaded completely..pls guide me in this regard
.ral:cr
June 16th, 2009, 08:33 AM
xml_loader.addEventListener(Event.COMPLETE, fnc)
MurtenSaerbi
June 16th, 2009, 08:53 AM
You can load the xml like this:
public function XmlLoader(path:String) {
loader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest(path);
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
And then configure listeners and wait for the complete signal:
private function configureListeners(dispatcher:IEventDispatcher):vo id {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}
private function completeHandler(event:Event):void {
xml = new XML(event.target.data);
dispatchEvent(new Event("evtXMLLoaded", {args: "done"}));
}
For instance. If you listen for that event you can easily know when the xml is fully loaded.
I have attached a xmlloader that I always use. You don't have to use it, but perhaps it is useful for you.
How to use it:
1. import it
2. create an instance of it.
3. add a listener and a handler function
4. done!
import utils.XmlLoader;
myLoader = new XmlLoader("xml/whateverFile.xml");
myLoader.addEventListener("evtXMLLoaded", dataLoaded);
private function dataLoaded(e:Event):void {
xml = new XML();
XML.ignoreWhitespace = true;
xml = e.target.xml;
trace(xml);
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.