30 posts
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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.

1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

Listen for xml complete load and then call Initialize.

http://www.republicofcode.com/tutorials/flash/as3xml/
30 posts
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in Romania
+1 more
SharkStudio says

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

767 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 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
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Contributed a free file of the month
  • Made it to the Authors' Hall of Fame
+3 more
yuanhao_viva says

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

30 posts
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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