Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 89

Programming actionscript 3.0
Table of Contents

Advertisement

{
trace(myArray[i]);
}
// output:
// one
// two
// three
What you cannot do is iterate through the properties of an object if it is an instance of a user-
defined class, unless the class is a dynamic class. Even with instances of dynamic classes, you
will be able to iterate only through properties that are added dynamically.
for each..in
The
loop iterates through the items of a collection, which can be tags in an
for each..in
XML or XMLList object, the values held by object properties, or the elements of an array. For
example, as the following excerpt shows, you can use a
the properties of a generic object, but unlike the
loop contains the value held by the property instead of the name of the property:
each..in
var myObj:Object = {x:20, y:30};
for each (var num in myObj)
{
trace(num);
}
// output:
// 20
// 30
You can iterate through an XML or XMLList object, as the following example shows:
var myXML:XML = <users>
</users>;
for each (var item in myXML.fname)
{
trace(item);
}
/* output
Jane
Susan
John
*/
<fname>Jane</fname>
<fname>Susan</fname>
<fname>John</fname>
for each..in
loop, the iterator variable in a
for..in
loop to iterate through
for
Looping
89

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents