Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Illogical loading order with XML 1

Status
Not open for further replies.

Sammybobo

Programmer
Apr 4, 2003
87
US
Please help! I cant understand the logic behind this. I have two XML files, Myxml1 and Myxml2, that I am loading into the first frame of my movie. Myxml1 contains an attribute with a date value that I need to extract to call up the appropriate node’s attribute in Myxml2. I need to manipulate the date value from Myxml1 by assigning it a variable in order to get to the right node in Myxml2. But the movie is switching the loading order, putting the Xml loading last and all non-XML-related values first. Below is the order I entered and the illogical order of loading I was served by the movie. What’s amiss?

My order of loading:
Load Xml1
Assign “XY” as variable for Xml1 nodes wanted
Manipulate “XY” variable as needed
Load Xml2
Use “XY” to find the appropriate node in Xml2

The movie’s order of loading:
Assigned “XY” (Undefined)
Manipulate “XY” (NAN, because it’s not found)
Use “XY” to find the appropriate node in Xml2 (Undefined)
Load Xml1 (values loaded here)
Load Xml2 (valued loaded here)
 
XML taks time to load in (not long, but still not instant) because there has to be a round trip made to the file - could be on your harddrive, CD or on the server.

So even if you ask the files to be loaded first then Flash just carries on through your movie as usual - it only deals with the XML when it comes back from the request you made.

To get around this put your code for setting the variables into the 'onload' event fired by the XML loading - that way the XML will be in place before you try and do anything with it.

Code:
myXML= new XML()
myXML.onLoad=function (){
//parseXML
//set your variables
}
myXML.load(xmlfile);
 
Wangbar, thanks so much. You are correct. I discovered the same explanation from the ActionScript Bible last night and decided to structure my coding as you explained. God bless you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top