13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with XML<br />

Traversing XML structures<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

One of the powerful features of XML is its ability to provide complex, nested data via a linear string of text characters.<br />

Wh<strong>en</strong> you load data into an XML object, ActionScript parses the data and loads its hierarchical structure into memory<br />

(or it s<strong>en</strong>ds a run-time error if the XML data is not well formed).<br />

The operators and methods of the XML and XMLList objects make it easy to traverse the structure of XML data.<br />

Use the dot (.) operator and the desc<strong>en</strong>d<strong>en</strong>t accessor (..) operator to access child properties of an XML object. Consider<br />

the following XML object:<br />

var myXML:XML =<br />

<br />

<br />

Baking Extravagant Pastries with Kumquats<br />

<br />

Contino<br />

Chuck<br />

<br />

238<br />

<br />

<br />

Emu Care and Breeding<br />

<br />

Case<br />

Justin<br />

<br />

115<br />

<br />

<br />

The object myXML.book is an XMLList object containing child properties of the myXML object that have the name book.<br />

These are two XML objects, matching the two book properties of the myXML object.<br />

The object myXML..lastName is an XMLList object containing any desc<strong>en</strong>d<strong>en</strong>t properties with the name lastName.<br />

These are two XML objects, matching the two lastName of the myXML object.<br />

The object myXML.book.editor.lastName is an XMLList object containing any childr<strong>en</strong> with the name lastName<br />

of childr<strong>en</strong> with the name editor of childr<strong>en</strong> with the name book of the myXML object: in this case, an XMLList object<br />

containing only one XML object (the lastName property with the value "Case").<br />

Accessing par<strong>en</strong>t and child nodes<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The par<strong>en</strong>t() method returns the par<strong>en</strong>t of an XML object.<br />

You can use the ordinal index values of a child list to access specific child objects. For example, consider an XML object<br />

myXML that has two child properties named book. Each child property named book has an index number associated<br />

with it:<br />

myXML.book[0]<br />

myXML.book[1]<br />

Last updated 6/6/2012<br />

106

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!