Make it so
Download PXP2 class and examples zip file.
The PXP2 class will do all the work for you and give you a nice little object with all your XML data. After you put PXP2 into your global class path - instructions - you’re ready to go.
There is just a little bit of code to write. The class constructor requires two arguments. A reference to a function that it can call when the parsing is complete and a string that is the path to the XML file.
Suppose the blogRoll XML listed above is in an XML file, named blogRoll.xml, located in the same folder as your FLA/SWF. Here’s a brief example of how you would load and parse it.
function runWhenParseComplete(o:Object): Void { // this funciton is going to run when the // XML is parsed and ready to go var len:Number = o.blog.length; for ( var i:Number = 0; i < len; i++ ) { trace(o.blog[i]); } } var parsedXML:com.polygeek.utils.PXP2 = new com.polygeek.utils.PXP2("blogRoll.xml", runWhenParsed);
That’s all there is to it.
If you’re new to code like this then I’ll go over what’s happening. Loading XML is an asynchronous event. If you write code to load XML it will do so but that’s going to take time. Even if that XML is on your local drive it’s going to take a few milliseconds to load it into the Flash player. In the meantime the next line of code, and probably a few hundred more, are executed. If that code requires data from your XML to work then you’ll have a problem.
I like analogies so I’ll give you one here. Suppose you order a pizza to be delivered to your house. What do you do next? Well, you could do lots of things but you don’t start running your eatPizza function until it arrives, right?
Nope, you hang out. You might get things ready, turn the game on, maybe set some plates and napkins on the coffee table. When the pizza arrives you’re ready to go. Now you can run your eatPizza function.
That’s how the loading and parsing of XML works. You initiate it and give the PXP2 class the information it needs to do its job - path to the XML and the function to send the object to and run when complete. That function, in our example it was runWhenParsed, is sort of like the address to deliver the pizza to. That’s where your going to meet the delivery person and get the pizza/object. Now your good to go.
Next-> Don’t tug on that. You never know what it might be connected to.











