Extensible Markup Language (XML) is a popular standard developed by the World Wide Web Consortium (W3C).

XML is an open architecture designed to allow the interchange of data between any platform or language on the Internet. The technology has caught on like wildfire, and you would be hard pressed to find any current application that doesn't use XML in some way or other. The complete XML specifications are available here.

In support of the standard, Macromedia has added XML functionality to the Flash Player. Why would you want to load XML data into Flash? There are several advantages. First, Flash has the unique ability to process XML on the client side on almost any platform. Typically, most XML transformations are handled on the server side because browser support for XML is sporadic at best. Second, Flash can seamlessly combine XML data with cool animation and sound.

The XML object also extends the functionality of Flash. URL-encoded query string variables are traditionally used to bring data into a Flash movie via the Load Variables function. Here is an example of a typical query string used in Flash:
 
name=Bill%20Gates&email=bill@microsoft.com&comment=Hello
 

Most browsers are limited to a header size of approximately 256 characters (including query string data). The XML object has no such limitation. This makes it an ideal method for bringing database content into your Flash movies. On top of that, the XML object allows you to import and integrate any XML-formatted data available on the Web into Flash.

The Flash XML object gives you all the tools necessary to bring in, parse, manipulate, and export XML-formatted data. The XML object API is well documented and available on the Macromedia Web site.

Loading the XML file
Before you start adding code to a Flash movie, it's a good idea to create a unique layer for your ActionScript. I typically create a layer for all elements of my Flash movie (Figure A) because it makes it much easier to isolate and troubleshoot problems later on.


Figure A
Put elements in different layers


The next step is to create an instance of the XML object and load in the XML file. You can do this with two lines of code:
 
cnetXML = new XML();
cnetXML.load("cnet.xml");

 

If you look at the Flash XML API, you will notice a function called parseXML. You will hardly need to use this function; parseXML is automatically invoked by load().

Flash Players that are older than version 5.0 will ignore your XML code because they lack support for the XML object. So you may want to create a JavaScript detection routine that checks the Flash Player version and redirects users if they have insufficient resources to access your movie.

Do you need help with Web Technologies? Gain advice from Builder AU forums

Related links

Comments

1

David Diomede - 09/06/05

I'm using this scrpit in a cd interface with multiple xml files. It works well, but the problem is that when i clik on a link to go to one frame and then go back to the previous frame the xml text keeps on appending itself to the end of the text. I would like it to only load that particular XML when requested. how can if ix this?

» Report offensive content

2

fhjhkljkl - 17/10/07

<div title="فاركس"><A href="http://www.forex.co.ir/" title="فاركس"><IMG alt="فاركس بروكر فوركست سيگنال اكسپرت" src="http://www.forex.co.ir/forex.gif"></A> <A href="http://www.meta-fx.com/" title="فاركس"><IMG alt="فاركس بروكر فوركست سيگنال اكسپرت" src="http://www.meta-fx.com/forex.gif"></A></div>
http://www.forex.co.ir/
http://www.meta-fx.com/

» Report offensive content

3

roro44 - 07/02/08

Thanks a lot
http://www.roro44.com

» Report offensive content

4

FX tarder - 22/07/08

Thanks a lot
http://gheymatha.com

<p><a href="http://www.gheymatha.com/">forex</a></p>

» Report offensive content

5

&Oslash;&cent;&Uacute;&macr;&Ugrave;‡&Ucirc;Œ &Oslash;&plusmn;&Oslash;&sect;&Ucirc;Œ&Uacute;&macr;&O - 30/11/09

thanks for this comment

http://yap.ir

<a href="http://www.yap.ir/">آگهی رایگان</a>

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

5

&Oslash;&cent;&Uacute;&macr;&Ugrave;‡&Ucirc;Œ &Oslash;&plusmn;&Oslash;&sect;&Ucirc;Œ&Uacute;&macr;&O - 30/11/09

thanks for this comment http://yap.ir <a href="http://www.yap.ir/">آگهی رایگان</a> ... more

4

FX tarder - 22/07/08

Thanks a lot http://gheymatha.com <p><a href="http://www.gheymatha.com/">forex</a></p> ... more

3

roro44 - 02/07/08

Thanks a lot http://www.roro44.com ... more

Log in


Sign up | Forgot your password?

What's on?

  • Optus Deal

    Broadband + home phone + PlayStation®3 in a single package price!