30 posts
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
  • Romania
+1 more
SharkStudio
says
So i am loading a xml file and after that i initialize something with ADDED _TO_STAGE and the xml loads after the initialize, I want to load the xml before initialize how to do that? See this example to understand more clearly
LoadXML();///this loads after Initialize
addEventListener(Event.ADDED_TO_STAGE, Initialize);///this loads first

I want to keep ADDED _TO_STAGE because without it file doesn`t work properly.

1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says

Listen for xml complete load and then call Initialize.

http://www.republicofcode.com/tutorials/flash/as3xml/
30 posts
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
  • Romania
+1 more
SharkStudio
says

Tryed that but it just give`s me a blank screen

767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says

Instead of adding an event listener after the xml load complete, try to first see if the object has already been added to stage. If it is, just simply call the Initialize function and if not, add an event listener. Like this:

if (stage) Initialize(null);
else addEventListener(Event.ADDED_TO_STAGE, Initialize);
66 posts
  • Author Level 2
  • Collector Level 1
  • Freebie
  • Featured Author
+3 more
yuanhao_viva
says

don’t forget removeEventListener.if not,xml will load by twice when swf load another swf.

30 posts
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
  • Romania
+1 more
SharkStudio
says

thank you guys. fixed this

....
LoadXML();

private function LoadXML():void
{
  var loader:URLLoader = new URLLoader(new URLRequest("xml/test.xml"));
  loader.addEventListener(Event.COMPLETE, Initialize);
}

private function Initialize(event:Event):void
{
   xml = new XML(event.target.data);
}
by
by
by
by
by
by