Skip to main content
April 18, 2006
Answered

Understanding onLoad (XML)

  • April 18, 2006
  • 4 replies
  • 347 views
I have the code below.
When I watch the process in the Debug window, I realize that the "traiterXML" function is done after all the code is processed. I think i don't grasp the way codes are treated. Is there an event i should call, or watch, making it sure the code after the ".load" call is run after the XML treatment has been done?
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Peter Lorent
The XML-object works like this:
When you instruct it to load a file it gets the file, parses it and then fires an event 'onLoad'. If you define an onLoad handler for the object, it will execute the statements.
But in the meantime, all other code on the frame will be executed too. So, all your code that depends on the XML-object must be in the onLoad-handler or, like shyaway suggested, you place the code on the second frame and instruct the playhead to go to that frame in the onLoad handler. Or you place all code in functions and call the functions from the onLoad handler.

4 replies

April 18, 2006
Thank you LuigiL.
Peter LorentCorrect answer
Inspiring
April 18, 2006
The XML-object works like this:
When you instruct it to load a file it gets the file, parses it and then fires an event 'onLoad'. If you define an onLoad handler for the object, it will execute the statements.
But in the meantime, all other code on the frame will be executed too. So, all your code that depends on the XML-object must be in the onLoad-handler or, like shyaway suggested, you place the code on the second frame and instruct the playhead to go to that frame in the onLoad handler. Or you place all code in functions and call the functions from the onLoad handler.
April 18, 2006
Thanks!
Participating Frequently
April 18, 2006
it's best to preload your xml before tampering with it.
in frame 1, in your onLoad code... function(success){
if(success){
gotoAndStop(2);
}else{
gotoAndStop(error_frame);

that should force your xml to load before going to frame 2.