Developer Guide
Using the and the for statements
ActionScript 3.0 includes the statement and the for statement for iterating through XMLList
objects. For example, consider the following XML object,
myXML, and the XMLList object, myXML.item. The
XMLList object,
myXML.item, consists of the two item nodes of the XML object.
var myXML:XML =
<item id='1' quantity='2'>
<item id='2' quantity='2'>
The statement lets you iterate over a set of property names in an XMLList:
var total:Number = 0;
for (var pname:String in myXML.item)
total += myXML.item.@quantity[pname] * myXML.item.price[pname];
The for statement lets you iterate through the properties in the XMLList:
var total2:Number = 0;
for each (var prop:XML in myXML.item)
total2 += prop.@quantity * prop.price;
Using XML namespaces
Namespaces in an XML object (or document) identify the type of data that the object contains. For example, in
sending and delivering XML data to a web service that uses the SOAP messaging protocol, you declare the
namespace in the opening tag of the XML:
var message:XML =
<soap:Envelope xmlns:soap=""
<soap:Body xmlns:w="">
<w:tempurature >78</w:tempurature>
The namespace has a prefix, soap, and a URI that defines the namespace,
ActionScript 3.0 includes the Namespace class for working with XML namespaces. For the XML object in the
previous example, you can use the Namespace class as follows:

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.