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 />

To access a specific grandchild, you can specify index numbers for both the child and grandchild names:<br />

myXML.book[0].title[0]<br />

However, if there is only one child of x.book[0] that has the name title, you can omit the index refer<strong>en</strong>ce, as follows:<br />

myXML.book[0].title<br />

Similarly, if there is only one book child of the object x, and if that child object has only one title object, you can omit<br />

both index refer<strong>en</strong>ces, like this:<br />

myXML.book.title<br />

You can use the child() method to navigate to childr<strong>en</strong> with names based on a variable or expression, as the following<br />

example shows:<br />

var myXML:XML =<br />

<br />

<br />

Dictionary<br />

<br />

;<br />

var childName:String = "book";<br />

trace(myXML.child(childName).title) // output: Dictionary<br />

Accessing attributes<br />

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

Use the @ symbol (the attribute id<strong>en</strong>tifier operator) to access attributes in an XML or XMLList object, as shown in the<br />

following code:<br />

var employee:XML =<br />

<br />

Wu<br />

Erin<br />

;<br />

trace(employee.@id); // 6401<br />

You can use the * wildcard symbol with the @ symbol to access all attributes of an XML or XMLList object, as in the<br />

following code:<br />

var employee:XML =<br />

<br />

Wu<br />

Erin<br />

;<br />

trace(employee.@*.toXMLString());<br />

// 6401<br />

// 233<br />

You can use the attribute() or attributes() method to access a specific attribute or all attributes of an XML or<br />

XMLList object, as in the following code:<br />

Last updated 6/6/2012<br />

107

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

Saved successfully!

Ooh no, something went wrong!