Chapter 19. XML

Introduction

The capability to load, parse, and send XML data was added to Flash in version 5, and it marked a significant advance in the ease of communicating complex data to and from a server script. Prior to the introduction of the XML class to Flash, the only way to load and send text data was to use URL-encoded values, as discussed in Chapter 18. XML is a superior alternative in many cases because, unlike URL-encoded data, XML data is structured. URL encoding is fine for passing simple data between Flash and server-side scripts, but for complex data or Unicode characters, XML generally works much better. For example, if you want to load data from a text file that represents a simple datatype such as a string, URL-encoded data, such as the following, can be loaded using a LoadVars object:

myString=a+string+value

However, when you want to load data from an external source and use that data to create an ActionScript object, you are presented with the problem of how to represent that data as a URL-encoded string. You might try something like the following, in which each property-value pair is separated by an asterisk (*), and each property is separated from its corresponding value by a vertical pipe (|):

myObject=prop0|val0*prop1|val1*prop2|val2

Once the string value is returned for myObject, you could use String.split( ) to recreate the elements that make up the object. Although you can get by with this approach, it is often much easier to represent complex values ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.