
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
150
|
Chapter 6: Statements
In Flash 4, set was called Set Variable, and it was often used to dynamically assign
variables that had programmatically generated sequential names. It allowed pro-
grammers to simulate arrays, which were not a native part of Flash 4 ActionScript.
Since arrays were added in Flash 5, set is rarely used anymore. In most cases, a vari-
able can be referenced dynamically with the object property access operator,
[]. For
example,
// Set the value of firstName in the form_mc movie clip.
form_mc["first" + "Name"] = "jane";
// Set the value of firstName in the current movie clip.
this["first" + "Name"] = "jane";
However, set is required when dynamically referring to a local variable in a function
(because local variables are not properties of any exposed ActionScript object).
The function Statement
Just as the var statement is used to declare (i.e., create) variables, the function state-
ment is used to declare functions. The function statement has the following syntax:
function funcName (param1, param2, param3,...paramn) {
statements
}
The keyword function begins the statement; funcName is the name of the function
being declared;
param1 through paramn define the parameters required by the func-
tion when it executes (parameters are separated by commas);
statements is a list ...