Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 326

Programming actionscript 3.0
Table of Contents

Advertisement

Similarly, the final line of following code generates an error because there is no
the second
element:
p
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(b == 'Bob'));
To avoid these errors, you can identify the properties that have the matching attributes or
elements by using the
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(attribute('id') == '123'));
trace(doc.p.(elements('b') == 'Bob'));
You can also use the
hasOwnProperty()
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(hasOwnProperty('@id') && @id == '123'));
trace(doc.p.(hasOwnProperty('b') && b == 'Bob'));
Using the for..in and the for each..in statements
ActionScript 3.0 includes the
iterating through XMLList objects. For example, consider the following XML object,
and the XMLList object,
nodes of the XML object.
item
var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2' quantity='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>;
326
Working with XML
and
attribute()
elements()
method, as in the following code:
statement and the
for..in
. The XMLList object,
myXML.item
methods, as in the following code:
statement for
for each..in
consists of the two
myXML.item,
property of
b
,
myXML

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents