How to process events chain.
- by theblackcascade
I need to process this chain using one LoadXML method and one urlLoader object:
ResourceLoader.Instance.LoadXML("Config.xml");
ResourceLoader.Instance.LoadXML("GraphicsSet.xml");
Loader starts loading after first frameFunc iteration (why?) I want it to start immediatly.(optional)
And it starts loading only "GraphicsSet.xml"
Loader class LoadXml method:
public function LoadXML(URL:String):XML
{
urlLoader.addEventListener(Event.COMPLETE,XmlLoadCompleteListener);
urlLoader.load(new URLRequest(URL));
return xml;
}
private function XmlLoadCompleteListener(e:Event):void
{
var xml:XML = new XML(e.target.data);
trace(xml);
trace(xml.name());
if(xml.name() == "Config")
XMLParser.Instance.GameSetup(xml);
else if(xml.name() == "GraphicsSet")
XMLParser.Instance.GraphicsPoolSetup(xml);
}
Here is main:
public function Main()
{
Mouse.hide();
this.addChild(Game.Instance);
this.addEventListener(Event.ENTER_FRAME,Game.Instance.Loop);
}
And on adding a Game.Instance to the rendering queue in game constuctor i start initialize method:
public function Game():void
{
trace("Constructor");
if(_instance)
throw new Error("Use Instance Field");
Initialize();
}
its code is:
private function Initialize():void
{
trace("initialization");
ResourceLoader.Instance.LoadXML("Config.xml");
ResourceLoader.Instance.LoadXML("GraphicsSet.xml");
}
Thanks.