The for each..in loop
iterates through the items of a collection, which can be tags in
an 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 for each..in loop to iterate
through the properties of a generic object, but unlike the for..in loop,
the iterator variable in a for each..in loop contains
the value held by the property instead of the name of the property:
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>
<fname>Jane</fname>
<fname>Susan</fname>
<fname>John</fname>
</users>;
for each (var item in myXML.fname)
{
trace(item);
}
/* output
Jane
Susan
John
*/
You can also iterate through the elements of an array, as this
example shows:
var myArray:Array = ["one", "two", "three"];
for each (var item in myArray)
{
trace(item);
}
// output:
// one
// two
// three
You cannot iterate through the properties of an object if the
object is an instance of a sealed class. Even for instances of dynamic
classes, you cannot iterate through any fixed properties, which
are properties defined as part of the class definition.