User Guide

60 Chapter 2: ActionScript Basics
To loop through the children of a movie clip or an object:
Use the for..in statement.
Children include other movie clips, functions, objects, and variables. The following example uses
the
trace statement to print its results in the Output panel:
var myObject:Object = { name:'Joe', age:25, city:'San Francisco' };
for (propertyName in myObject) {
trace("myObject has the property: " + propertyName + ", with the value: " +
myObject[propertyName]);
}
This example produces the following results in the Output panel:
myObject has the property: name, with the value: Joe
myObject has the property: age, with the value: 25
myObject has the property: city, with the value: San Francisco
You might want your script to iterate over a particular type of child—for example, over only
movie clip children. You can do this using
for..in with the typeof operator.
for (myname in my_object) {
if (typeof (my_object[myname]) == "anObject") {
trace("I have an object child named " + myname);
}
}
For more information on each action, see the individual entries in Flash ActionScript Language
Reference:
while, do while, for, for..in.
Using built-in functions
A function is a block of ActionScript code that can be reused anywhere in a SWF file. If you pass
values as parameters to a function, the function will operate on those values. A function can also
return values.
Flash has built-in functions that let you access certain information and perform certain tasks, such
as getting the version number of Flash Player that is hosting the SWF file (
getVersion()).
Functions that belong to an object are called methods. Functions that dont belong to an object are
called top-level functions and are found in the Functions category of the Actions panel.
Each function has individual characteristics, and some functions require you to pass certain
values. If you pass more parameters than the function requires, the extra values are ignored. If you
dont pass a required parameter, the empty parameters are assigned the
undefined data type,
which can cause errors during runtime. To call a function, it must be in a frame that the playhead
has reached.
To call a function, simply use the function name and pass any required parameters:
isNaN(someVar);
getTimer();
eval("someVar");
For more information on each function, see its entry in Flash ActionScript Language Reference.