03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The for..in statement iterates over properties of objects in the iterated object's prototype<br />

chain. Properties of the object are enumerated first, then properties of its immediate<br />

prototype, then properties of the prototype's prototype, <strong>and</strong> so on. The for..in statement<br />

does not enumerate the same property name twice. If the object child has prototype parent<br />

<strong>and</strong> both contain the property prop, the for..in statement called on child enumerates prop<br />

from child but ignores the one in parent.<br />

The curly braces ({}) used to enclose the block of statements to be executed by the for..in<br />

statement are not necessary if only one statement will execute.<br />

If you write a for..in loop in a class file (an external AS file), then instance members are not<br />

available for the loop, but static members are. However, if you write a for..in loop in a FLA<br />

file for an instance of the class, then instance members are available but static ones are not.<br />

Parameters<br />

variableIterant:String - The name of a variable to act as the iterant, referencing each<br />

property of an object or element in an array.<br />

Example<br />

The following example shows using for..in to iterate over the properties of an object:<br />

var myObject:Object = {firstName:"Tara", age:27, city:"San Francisco"};<br />

for (var prop in myObject) {<br />

trace("myObject."+prop+" = "+myObject[prop]);<br />

}<br />

//output<br />

myObject.firstName = Tara<br />

myObject.age = 27<br />

myObject.city = San Francisco<br />

The following example shows using for..in to iterate over the elements of an array:<br />

var myArray:Array = new Array("one", "two", "three");<br />

for (var index in myArray)<br />

trace("myArray["+index+"] = " + myArray[index]);<br />

// output:<br />

myArray[2] = three<br />

myArray[1] = two<br />

myArray[0] = one<br />

The following example uses the typeof operator with for..in to iterate over a particular<br />

type of child:<br />

for (var name in this) {<br />

if (typeof (this[name]) == "movieclip") {<br />

trace("I have a movie clip child named "+name);<br />

}<br />

}<br />

Statements 183

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

Saved successfully!

Ooh no, something went wrong!