03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - 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.

output<br />

myObject.firstName = Tara<br />

myObject.age = 27<br />

myObject.city = San Francisco<br />

The following example uses 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 />

Note: If you have several movie clips, the output consists of the instance names of those clips.<br />

The following example enumerates the children of a movie clip <strong>and</strong> sends each to Frame 2 in<br />

itsrespective Timeline. The RadioButtonGroup movie clip is a parent with three children:<br />

_RedRadioButton_, _GreenRadioButton_,, <strong>and</strong> _BlueRadioButton_.<br />

for (var name in RadioButtonGroup) { RadioButtonGroup[name].gotoAndStop(2);<br />

}<br />

function statement<br />

Usage 1: (Declares a named function.)<br />

function functionname([parameter0, parameter1,...parameterN]){<br />

statement(s)<br />

}<br />

Usage 2: (Declares an anonymous function <strong>and</strong> returns a reference to it.)<br />

function ([parameter0, parameter1,...parameterN]){<br />

statement(s)<br />

}<br />

Comprises a set of statements that you define to perform a certain task. You can define a<br />

function in one location <strong>and</strong> invoke, or call, it from different scripts in a SWF file. When you<br />

define a function, you can also specify parameters for the function. Parameters are<br />

placeholders for values on which the function operates. You can pass different parameters to a<br />

function each time you call it so you can reuse a function in different situations.<br />

Use the return statement in a function's statement(s) to cause a function to generate, or<br />

return, a value.<br />

216 <strong>ActionScript</strong> language elements

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

Saved successfully!

Ooh no, something went wrong!