This is probably a common issue, but I can’t figure it out. I have a class in which I load a XML file. I want to find a possibility to use the XML data so I can add some movieclips on the Stage.
This is the class:
package GalleryPackage{
import flash.net.*;
import flash.events.*;
import flash.display.Sprite;
public class xmlParser extends Sprite{
public var textData:TextLoader;
var xmlObj:XML;
public function xmlParser(url:String){
textData=new TextLoader(url);
textData.loader.addEventListener(Event.COMPLETE,completeHandler);
}
private function completeHandler(e:Event){
xmlObj=new XML(textData.loader.data);
trace(xmlObj);
}
}
}
This is the textLoader class:
package GalleryPackage{
import flash.display.Sprite;
import flash.net.*;
import flash.events.*;
public class TextLoader extends Sprite {
public var entireText:String=new String();
public var loader:URLLoader=new URLLoader();
public function TextLoader(url:String) {
var URLrequest:URLRequest=new URLRequest(url);
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.load(URLrequest);
loader.addEventListener(Event.COMPLETE,completeHandler);
}
private function completeHandler(e:Event) {
entireText=loader.data;
trace(entireText);
}
}
}
My problem is that I don’t know (on the Stage) when the XML has finished loading, so I can use it. I have tried using EventDispatcher, but probably I’m too noob :|.
Please give me an idea how to accomplish this.