ActionScript statements have
a certain scope, or area
of effect within which they are valid. When a statement is attached
to a movie clip, that statement’s scope is limited to the clip
that bears it. For example, here we refer to a variable,
score, in an assignment statement:
score = 10;
If that statement were attached to
clipA, then the
interpreter would set the value of
clipA, because the statement is
clipA. If that statement
were attached to
clipB, the interpreter would set
the value of
because the statement is scoped to
location of the statement determines its scope, and, hence, its
Statements in the body of a function operate in their own, separate scope, called a local scope. A function’s local scope is like a private phone booth for the function, distinct from the scope of the clip or object to which the function is attached. The local scope of a function is created when the function is invoked and destroyed when the function finishes executing. When resolving variables referenced in the statements of the function body, the interpreter looks first in the function’s scope.
Function parameters, for example, are defined in the local scope of a function—not the scope of the timeline that bears the function. Parameters, hence, are accessible to the statements of a function’s body only while the function is running. Statements outside the function have no access to the function’s parameters.
A function’s local scope ...