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

Reading and parsing XML data<br />

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

The RSSParser class includes an xmlLoaded() method that converts the input RSS data, stored in the rssXML variable,<br />

into an string containing HTML-formatted output, rssOutput.<br />

Near the beginning of the method, code sets the default XML namespace if the source RSS data includes a default<br />

namespace:<br />

if (rssXML.namespace("") != undefined)<br />

{<br />

default xml namespace = rssXML.namespace("");<br />

}<br />

The next lines th<strong>en</strong> loop through the cont<strong>en</strong>ts of the source XML data, examining each desc<strong>en</strong>dant property named item:<br />

for each (var item:XML in rssXML..item)<br />

{<br />

var itemTitle:String = item.title.toString();<br />

var itemDescription:String = item.description.toString();<br />

var itemLink:String = item.link.toString();<br />

outXML += buildItemHTML(itemTitle,<br />

itemDescription,<br />

itemLink);<br />

}<br />

The first three lines simply set string variables to repres<strong>en</strong>t the title, description and link properties of the item<br />

property of the XML data. The next line th<strong>en</strong> calls the buildItemHTML() method to get HTML data in the form of an<br />

XMLList object, using the three new string variables as parameters.<br />

Assembling XMLList data<br />

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

The HTML data (an XMLList object) is of the following form:<br />

itemTitle<br />

<br />

itemDescription<br />

<br />

<br />

More...<br />

<br />

<br />

The first lines of the method clear the default xml namespace:<br />

default xml namespace = new Namespace();<br />

The default xml namespace directive has function block-level scope. This means that the scope of this declaration<br />

is the buildItemHTML() method.<br />

The lines that follow assemble the XMLList, based on the string argum<strong>en</strong>ts passed to the function:<br />

Last updated 6/6/2012<br />

115

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

Saved successfully!

Ooh no, something went wrong!