sfmultimedia.net

sfmultimedia :: actionscript salons :: wrangling xml

/

Actionscript Salon #12:
The Joy of X -
Wrangling XML Data in Flash

XML (eXtensible Markup Language) has gained in popularity over the last few years, largely on account of its simplicity and interoperability. Most databases and many other programs can read and write in XML, making it a useful format for deploying information across multiple applications. The key is that XML divorces content from presentation.

Since version 5, Flash has been leveraging XML with increasing deftness. This month, the Salon will look at XML parsing, how we can apply this technology to build simpler, more powerful websites, and of course some of the common difficulties developers encounter when wrestling the Whomping Willow that is the XML tree.

As part of this demonstration, we’ll build a slideshow similar to the Remoting slideshow last month, but this time placing our data into an XML flat-file database.

Relevance/availability: the techniques discussed here are essentailly relevant to any version of Flash from 5 forward. But note that XML handling has been massively overhauled in Actionscrpt 3 (search E4X).

Simple XML Load. File which simply shows how to load an XML file into Flash, just 4 lines of code. We used this to demonstate how heavy an XML file is when brought into Flash (press ctrl-shift Enter to launch the swf with the debugger and see the XML Object).

This file is zipped with a very basic XML doc.

Download the .fla file (Zip 3k)

Slide show: XML Load with up-front data parsing. The top thirty lines or so of this file show how to load and parse a sample XML schema. Everything after that is implementation of a simple slide show utilizing the data we've teased out of the XML.

This file is zipped with the XML file, but not with the corresponding images. Please download the images zip below if you want to see the whole thing in action.

View the swf

Download the .fla file (Zip 173k)

Slide Show: XML Load without data parsing. Exactly the same as the above file, except no data parsing. Instead, whenever we need data, the AS crawls directly into the XML tree and grabs it.

This file is zipped with the XML file (same as in the previous version), but not with the corresponding images. Please download the images zip below if you want to see the whole thing in action.

View the swf

Download the .fla file (Zip 173k)

Bouncing Pictures Slide Show. This file uses the exact same data and data parsing as the XML Load with up-front data parsing, but with completely different visual results. We're demonstrating here the value of separating content from presentation. The data and the presentation needn't know anything abouit each other in order to work.

This file is zipped with the XML file (same as in the previous versions), but not with the corresponding images. Please download the images zip below if you want to see the whole thing in action.

View the swf

Download the .fla file (Zip 27k)

Download the images zip (491k)

Download everything (flas, swfs, xml and images -- 1.3Mb)