I’m trying to parse some data from a XML file.
Now, I want to display the result in a main class NOT in the _onLoadXML function. For some reason I can’t see the result of xmlData, no data outside of _onLoadXML function.
How can I do that?
package manageXML {
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class LoadXML extends EventDispatcher {
private var loader:URLLoader;
private var xmlData:XML;
public function LoadXML(filename:String):void {
this.loader = new URLLoader();
this.loader.addEventListener(Event.COMPLETE, _onLoadXML);
this.loader.load(new URLRequest(filename));
trace(getxmlData()); // it returns obviously NULL
}
private function _onLoadXML(evt:Event):void {
try {
this.xmlData = XML(URLLoader(evt.target).data);
trace(this.xmlData); // it works fine here but NOT from the OUTSIDE
dispatchEvent(new Event(Event.COMPLETE));
} catch (error:Error) {
trace("Can't load" + error.message);
}
}
public function getxmlData():XML {
return this.xmlData;
}
}