
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The ActionScript Statements
|
149
Function calls are the most powerful type of expression statement. Even if a function
doesn’t return a useful value, it may have a very useful side effect. For example,
gotoAndStop() returns the value
undefined but has an important side effect—it moves
the playhead to another frame:
gotoAndStop(5); // The value of _currentframe is changed to 5.
We’ll learn more about function calls in Chapter 9 under “Running Functions.”
The var Statement
The var statement declares a new variable:
var x;
You can assign the new variable’s initial value as part of a var statement:
var x = 10;
When used outside a function, the var statement creates a variable scoped to the
timeline containing the statement. When used inside a function, the var statement
creates a variable local to that function (i.e., one that dies when the function fin-
ishes). Refer back to Chapter 2 for more information on variables.
The set Statement (Set Variable)
For most variable assignments, we use an assignment expression in statement form,
like this:
x = 30;
This kind of expression, however, requires us to know the name of our variable in
advance. If we want to generate the name of a variable dynamically during an assign-
ment, we can use the set statement, which has the following syntax:
set(variable