30 posts
  • Exclusive Author
  • Bought between 1 and 9 items
  • Romania
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
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.

1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 more
Tean says

Listen for xml complete load and then call Initialize.

http://www.republicofcode.com/tutorials/flash/as3xml/
30 posts
  • Exclusive Author
  • Bought between 1 and 9 items
  • Romania
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
SharkStudio says

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

767 posts
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
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 had a Free File of the Month
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 1 and 9 items
  • Has been a member for 3-4 years
  • China
yuanhao_viva says

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

30 posts
  • Exclusive Author
  • Bought between 1 and 9 items
  • Romania
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
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