Hello everyone. This is my first post to the list! I'm a graphic designer who until recently lived in Photoshop. I'm just moving over to Flash and AS so please be kind. =)
A customer has given me an XML file template and is asking me to figure out how to load this into Flash. I think this can be done as many of you Flash experts do this. I read a tutorial and think I can figure out how to read the file but I'm new to parsing information. Never tried it before. Can anyone offer suggestions how to do this for a newbie? Also, how do I read the information once it's parsed? Does the XML get copied into an array or some kind of object maybe?
You're going to be working with variables, arrays, and functions for this one, so be prepared to learn about using those. When learning flash, don't forget about the flash help resource in the program itself. Do a search for XML in the flash help and in the results scroll down to "ActionScript 2.0 Language Reference"--find XML in there and study that to learn the basics of how XML works in flash. The general procedure for XML in AS2 is to create a variable that will hold your XML data, a function loads the XML data into the variable, using scripts like "childNodes", "nextSibling", and "attributes" to drill down into the XML tree and assign the values from your XML into variables and arrays, and then finally take the values in those variables and arrays and use them. The thing that stumped me the most was the asynchronous loading of the XML data which means that the XML does not load in relation to the flash document--it loads at its own pace and actually takes a few milliseconds to complete, so if you load your xml in the first frame and your trying to use data from the xml in the next frame (without a stop inbetween) you're going to find that the variables are undefined because the xml hasn't finished loading yet... the trick is to use a stop which doesn't let the playhead go to the next frame until the xml has finished loading and populating the variables. I think the actual time the xml takes to load is around 1/8 of a second (5 frames at 40fps)--I seriously spent something like 3 or 4 days trying to figure out why my variables kept coming back undefined when my code was right--checking and rechecking my code. Some other useful resources on learning XML in flash are: www.kirupa.com and this page http://www.flashguru.co.uk/links/ where you will find more links to resources. Good luck.
A good question would be: what will you do with the info once parsed? will you instantiate a "page" object? Will you put it into an array? I ask this because the parsing method needs know where to put the info it reads from the xml.