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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Working with XML<br />

copy()<br />

l<strong>en</strong>gth()<br />

valueOf()<br />

For details on these methods, see the ActionScript 3.0 Refer<strong>en</strong>ce for the Adobe Flash Platform.<br />

For an XMLList object that contains exactly one XML elem<strong>en</strong>t, you can use all properties and methods of the XML<br />

class, because an XMLList with one XML elem<strong>en</strong>t is treated the same as an XML object. For example, in the following<br />

code, because doc.div is an XMLList object containing one elem<strong>en</strong>t, you can use the app<strong>en</strong>dChild() method from<br />

the XML class:<br />

var doc:XML =<br />

<br />

<br />

Hello<br />

<br />

;<br />

doc.div.app<strong>en</strong>dChild(World);<br />

For a list of XML properties and methods, see “XML objects” on page 99.<br />

Initializing XML variables<br />

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

You can assign an XML literal to an XML object, as follows:<br />

var myXML:XML =<br />

<br />

<br />

burger<br />

3.95<br />

<br />

<br />

fries<br />

1.45<br />

<br />

<br />

As the following snippet shows, you can also use the new constructor to create an instance of an XML object from a<br />

string that contains XML data:<br />

var str:String = "burger"<br />

+ "3.95";<br />

var myXML:XML = new XML(str);<br />

If the XML data in the string is not well formed (for example, if a closing tag is missing), you will see a run-time error.<br />

You can also pass data by refer<strong>en</strong>ce (from other variables) into an XML object, as the following example shows:<br />

Last updated 6/6/2012<br />

103

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

Saved successfully!

Ooh no, something went wrong!