The Flash-XML FAQ aims to provide a definitive source for common questions about Flash and its interaction with XML (and XML datasources). If you think of a questions that should be answered in this FAQ, or have an answer or a better answer to a question in this FAQ please email Luke Tupper

Copyright Luke Tupper 2001-2002

The latest version of this FAQ is kept at:

The latest version of this FAQ is 2.0.0

A change log is kept at:

FAQ Mirrors:

FAQ Translations

Email Luke if you are willing to be included in the official mirrors list.

Before You Begin What is XML?

XML is the extensible markup language. XML uses tags very similar to HTML, instead of describing the structure of the page the tags, XML uses the tags to describe the data. This allows a structured data format, that can be extended without breaking previous implementations. A good starting point for learning XML is:

Why should I use XML?

XML is becoming a standard way for people to export and import data from different systems. Its simplified mark up language make it easy for different systems to read data in, without knowing the exact structure of the data. If the XML data description has been properly created it is possible to add additional information to your XML data files without affecting system that are already using the information.

If you load XML data into flash, an object model will be created that will allow you to easily manipulate and extract the data. The same object model is available to create XML data, and export it to an extenal system.

Why can't I simply load the information from a simple file?

For retrieving information external to the flash file loadvariables might work when loading simple or small amounts of information. Once you have to retreive information where the amount of information changes, or is being created by an external source, you should use XML

Connectivity Why did my movie stopped working when I have uploaded it to a web server

When run from a web server Flash has a security implementation which only allows you to send and retreive information to the server that delivered the flash file. If you try to read information from another system (such as you will find that the XML files will work fine on your local machine, but will fail when you move them onto your web server.

In nearly all browsers this is the server which the HTML file contains your flash file. However at least IE4.5 for the Mac, will only allow you to send and retrieve information to the server that contains the flash file. For this reason it is recommended that you place you flash file and HTML file on the same server.

How do I get information from server X to use in flash?

Your ability to use external XML sources will depend on the amount of access you have to your web server. Before using these routines make sure you have permission to access this external information.

The following routines will extract the information from an external web server and retransmit it from your own machine, avoiding the security problems outlined in 2a. If you know how to perform these routines using a different server based language please submit them to:





Java Servlets:


Mod-ReWrite on Apache:




Shell Scripting:

Manipulating XML Why do carriage returns, linefeeds and tabs appear as blank XML nodes?

When flash loads XML data by default any carriage returns and linefeeds are displayed as empty XML nodes. The exact reason that Macromedia did this is unclear however, when writing code to manipulate XML information it is important to make sure you always check the node XML object to make sure it is not a blank node. Do this by checking the node name to make sure you have correct node, this will also ensure that if extra data is added to the XML your movie will still work.

How do I remove the whitespace XML nodes?

With versions of the flash player after version 5.0.41 there is the command xml.removeWhitespace however unless you are working in a controlled environment where you can rensure that the flash player is the latest this will be of no use.

First thing the whitespace command only works for people with the latest versions of flash, so if they have an earlier version then it will not work. A better option is to get the whitespace stripped out using this code:

Go to the very last script on the page and you should find a fla file with whitespace stripping code. This will work with any flash player.

Why do I get a timeout error when parsing the XML?

If your XML is extremely large it may take flash a long time to process your XML. If this takes longer than 15 seconds, the flash player will throw an error. You cannot change this error, or its timeout. Your options will be to reduce the size of your XML file or load and parse it in several chunks. It has been found that attributes are a lot quicker to access and parse than child nodes.

Back End Integration Can I use ASP/JSP/PHP/Perl/Servlets/ColdFusion/Whatever to create my XML files dynamically

Any backend scripting language should be able to create XML files. As long as you can output properly formatted XML from your scripting language flash will be able to load the information. Flash does not require that the file has a .xml extension.

In fact web pages that conform to the XHTML spec can be read and parsed by flash.

How do I debug connectivity problems between flash and the XML script?

The first thing to do is make sure the XML is being outputted correctly. The easiest way to do this is to use a web browser to read in the information. Internet Explorer is a good test as it will render the XML in a tree structure as well as color the nodes and attributes.

How do I configure coldfusion to output XML?

How do I read XML data into the server using PHP?

You should not have to have a php script that parses the data back together if you set the content type of the xml to "text/xml". This was a bug in version 5,0,30,0 (the initial released version with the dev studio). See link: It always sends a content type of "application/x-www-form-urlencoded". But in version 5,0,42,0 (only through the webbrowser) of the player you have a new XML member called contentType that I can set the type to "text/xml". Now, when I do this $HTTP_RAW_POST_DATA will be set with my XML and not chopped into nasty key value pairs.

And the second minor tidbit, for PHP developers: In version 4.0.7 there will be a config directive to force $HTTP_RAW_POST_DATA to stay set no matter what. For those of you interested, here's my code (and it seems to work for me - heavily borrowed from macromedia example):


xmlreader.php PHP CODE:

LOGIN OK'; ?> ]]>

and I end up with an xmloutput.txt file with this in it:


Another options is:

Anyway the kludge is to do some parsing in PHP before invoking the XML engine. The faulty content-type is causing PHP to parse the data as if it were url encoded ('attribute1=value1&attribute2=value2...') and place it in $HTTP_POST_VARS instead of $HTTP_RAW_POST_DATA where the XML engine expects it. It's trivial to set things right once you know what's gone wrong:

Then just proceed as normal, invoking your XML parser of choice...

How do I read XML data into the server using ASP?

The ASP should use the Microsoft XML Parser to read the XML elements and traverse the tree.

To get the XML in, try assigning the whole post data to a variable.

How do I read XML data into the server using Perl?

This example script takes 2 parameters in the URL and saves the data into a xml file on the server.

"; #} #At this point, our name=value pairs have been decoded into their original form. Now we can put them into a hash that our script can use. #Since $name corresponds with a specific form element, we'll use that as the index. That way, if we want to access the value in, say, a #textbox, we can do that with #$first_name = $form_data{'first_name'}; # File manipulation $fileNameToOpen = $form_data{'name'}; open myHandle, ">$fileNameToOpen"; $XMLtoWrite = $form_data{'xml'}; print myHandle $XMLtoWrite; close myHandle; print "Here's the XML: ".$XMLtoWrite; ############## ### End Script ############## ]]>
The XML I am loading is being cached by my browser, how can I stop this?

The random number solution is simply trick the browser/proxy server into thinking it is getting a new file, because the URL has changed.For example if I am loading:

And this file is changing the browser will see the request for the URL and know that it is the same one and will not make an update.If I change the URL to be:

Where the last number is random. For the web server it will simply ignore this random=12923434 number, as it is just a file. However the browser and proxy servers are unable to determine that this is the same as the file before and will be forced to reload the file, as they are not able to determine that the files are the same. If you make the 'random' number based on date and time you can guarentee that the random numbers will not be repeated.

Scripting Why is the xml.onload call made?

The xml.onload property which you can set with the name of a function. Once the XML file has been loaded and parsed by the flash player your function will then be called. Your function should take a single parameter which flash will pass to you specifing whether the XML file was successfully loaded. Check this before trying to access your XM Ldata.

How do I access node values?

Node values are the values between tags in XML. Eg the node value in the following XML for the my-xml tag:

is "Flash is great"

Once you have parsed through your tree and found node you want to access you can use the .nodeValue property to retreive the text of that node. Eg:

Using the nodeValue function is not really necessary (although it is good form) you can simply use:

The same results will be returned as the first statement. You can use these methods for setting the node values as well.

How do I access attributes?

Attributes assigned inside a XML tag. For example the attributes of the tag my-xml:

Flash is great]]>

are QuoteFrom and Display.

Attributes are accessed in Flash using the attributes tag in two ways:


The attributes node can be used for assigning attributes to XML as well as accessing attributes. Adding a new attribute is done as such:

This will result in xml looking like:

Is it better to have an XML file with values or attributes?

Well either option is applicable. Both will deliver you the data that you require. Vaykent has done some tests recently and found XML with attributes load a lot quicker than XML with a large number of nodes. (Note this information is current for Flash 5.

How do I make XML work quicker?

The smart guys at figleaf have a better way: XMLNitro 1.3 beta

This routine replaces the standard XML routines and gets a 75~130% increase in speed. And se the diskussion around it....

Flash/XML Socket Servers What does a socket connection do for me that a normal xml file doesn't?

A socket connection is different in one fundamental way from normal data-pushing in flash. Under normal circumstances, the Flash client must always ask for data from the server. But when you create a socket connection in Flash, the client 'listens' to the server, and the server can initiate the connection to the client. This is the key to multi-user environments, where the server acts as an intermediary between multiple Flash clients. It involves taking data such as instant messages from one client and then sending it to another client. Napster, RealAudio, Telnet, these all use sockets to communicate with the server, the same way that we want Flash too.

XML data that is brought into Flash through sockets is exactly the same as normal XML objects. The only difference is the process involved in getting data into Flash.

What is needed to make a Socket Connection?

You need a XML server that is capable of accepting socket connections. If the flash movie is delivered from the a web server, the XML socket server must be running on the same server, or from the same subdomain. (eg a flash movie on can read a file from

What does a XML Socket Server do?

An XML socket server is a piece of software that resides on the server and 'listens' on a 'port' for XML information from a client. When it receives information from a client it looks at the XML tags, and then performs some sort of action, such as broadcasting the information to other clients. XML socket servers can do many different tasks, some of them work with databases, others simply 'echo' information. An XML socket server can be written in Java, Python, C++ etc, and incorporate any number of features.

What can I expect of a Socket Server for Flash?

Right now the actual functionality of most Socket Servers for Flash revolve around chat. FlashNexus also allows for creation of custom tags in addition to it's normal <chat> tags. Fortress allows the creation of Java and Javascript plugin functionality making it probably the most robust XML socket server. Most are still in the 1.0 phase, and provide basic functionality and nominal security. None have real database functionality so that integrating your chat application or game with other parts of your site might pose a problem.

What kind of socket server is right for me?

If you would like to learn more about how XML sockets work, download and look at MoockComm. If you are looking for a chat or simple game server then FlashNexus is a wonderful app. If you want Java use Drserver. If you need to integrate your Flash app with an existing database, such as a mySQL server, need security and enterprise class stability then your only option currently is Fortress.

What socket servers are currently available?

There are many different flavors of servers in many different languages and each one has its strengths and weaknesses.

FlashXML Perl tarball and info:

Freeware. Source code available.

Perl code snippets and .fla client.

Compact XML Flash XML Socket Server:

Perl code for generic flash chat client. By Vaykent, sample below:

Perl code sample:

1, LocalPort => 2229); $selectObj = new IO::Select($manager); $/ = "\0"; while(@readySockets = $selectObj -> can_read){ foreach (@readySockets){ if($_ == $manager){ $newConnection = $manager -> accept; $selectObj -> add($newConnection); } else{ my $sysreadReturn = sysread($_, $infoRead, 2048); if($sysreadReturn == 0){ $syswriteToClient = syswrite($_, '', 2048); if($syswriteToClient==undef){ $selectObj -> remove($_); } } else{ foreach $eachClient ($selectObj->handles){ $syswriteToEachClient = syswrite($eachClient, $infoRead, 2048); } } } } } ]]>

Drserver XML Socket Server

Freeware. Source code available.

A great start at coding a chat server in Java. Not a servlet, but a multi-threaded Server object. I've had a couple errors and the fla isn't very robust but overall well-thought out and nearly there.


Freeware. Source code available.

Alpha software currently at 0.1pre2. Written in Python.


Commercial Server Software.

Windows and Linux server software. 5-user demo available or $95.00 64-user full version.

MoockComm: Chat client/server

Freeware. Source code available.

Colin Moock's simple chat client. Written as an illustration of coding in Flash with XML. Best beginner app to understand the intricacies of XML in Flash (I also recommend FlashNexus's chat client).


Freeware. Source code available.

Windows based server software built specifically for chat. Well-built freeware with MS Access database functionality and the ability to build custom tags. Allows execution of SQL statements from flash.

In-A-Flash- Message Board and Avatar Based Chat

Commercial Server Software.

Flash-XML based message board and avatar chat. Allows a custom front and back end. Requires Linux 5.0 or newer(whatever that means) ,Perl 5.004 or newer, Apache 1.2 or newer. Evaluation copy available.


Commercial Server Software.

The flash XML enterprise, mission-critical solution. Licensed-only on a per-server per user basis. The client is rather impressive, has everything you'd expect, plus top-class support and security. From the website: "activities taking place in any given room can be customized with simple plugins written in Java[tm] or JavaScript." Also available are Fortress Hosting Solutions at . Evaluation copy available.


Linux, FreeBSD, Unix, and Win32 with cygwin.

Jabber server supports flash5 xmlsocket connections directly. This means is that flash clients canconnect to the Jabber server as a normal Jabber client, and speak the normal Jabber XML protocol. One (not updated recently) such example is and Disney is also starting to roll out some flash games on their site that use this. It also has support for 'Transports' which allow you to extend the capabilities of the server to include AIM, IRC, Yahoo, and MSN protocols, allowing your flash clients to communicate to anyone on these networks.

AquaServer 1.5

Freeware. Java.

Basic XML socket server and demo client. Comes with java source if you'd like to explore it. Yet another useful tidbit from Fig Leaf Software.

XML Socket Programming Is it simple to set up and use XML Socket Servers?

Unfortunately the learning curve for using Flash and sockets is rather steep. It requires advanced knowledge of object-oriented concepts in ActionScript, and intermediate knowledge of web servers at the very least. You are better off with knowing a programming language or some server side scripting in order to make things really work. If you are looking for an easy flash chat app then steal some code from flashKit. XML socket servers offer advanced functionality for advanced flash apps.

What general issues exist with Socket Servers?

Socket servers must open a connection with a client using a port. Ports are numbered 0 to 65535. Flash requires the port number must be greater than 1024. Flash also requires that the server's domain be the same as that of the site, same as a normal data connection from Flash. Standard issues with XML, such as being unable to use XML objects anywhere but the _root, still exist with XML socket data, the only difference between XMLSocket data and XML data is the way that it is retrieved.

Do I get an indication from the Flash Player if the socket closes for some reason?

XMLSocket.onClose (page 422 of the ActionScript Reference Guide) allows you to set a callback function when the connection is closed by the server.In all the socket is pretty simple, with the following commands:

What firewall issues exist when opening a socket connection in Flash?

The same issues exist that will if you want to let real audio or any other protocol through. The firewall has to be set up to allow the connections to be created on the appriorate port. It's sort of common courtesy for certain ports to be certain kinds of data, such as HTML data runs over port 80, and Telnet on 22, FTP on 21, Napster on 6969. Most Firewall and Proxy software are constantly updated for these programs to allow data through these common ports, but block any data on others. So if you use a port that's not commonly used then it might be blocked on computers behind a firewall, and flash will simply not be able to communicate unless the client's network administrator specifically enables that port. If you decide to use a commonly used port, such as say Napster's 6969 and your clients are running Napster, then Flash will receive Napster's data and vice versa, completely kludging things up.

My Server sends out XML but my Flash application never receives it?

Your XML server must terminate each XML messages with a null (ASCII 0) otherwise your flash application will hold open a connection until the session is closed. If you are having problems have a look at some of the prebuilt flash servers that are known to be working and test with those, before using your own server. Then you can concentrate on problems in your flash code or your socket server.

Resources Where are some references so that can I learn about XML?

Where are some references so that can I learn about flash?

Where can I learn about scripting actionscript with XML?

What tutorials are available for learning XML and flash?

Thanks and Acknowledgements Authors

Founding Author: Luke Tupper


Flash-Sockets Author: Chris Hill


Thanks to everyone who has helped in defining this FAQ either via email or on the FlashKit Forum.

Naveen Rao






Japanese Translation: Jun Kitazawa

Acknowledged Sources

The following books were used in the creation of this FAQ:

Flash 5 Magic, New Riders, ISBN 0-7357-1023-6

ActionScript The Definitive Guide, O'Reilly, ISBN 1-56592-852-0