
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Variable Scope
|
55
Prior to introducing support for dot syntax in Flash 5, Flash supported an older
“path” style syntax that used backslashes instead of dots. Flash MX still supports the
legacy syntax, but you should update it to the more modern dot syntax as described
in Table C-2 in Appendix C.
Movie Clip Variable Life Span
Earlier, we said that the scope of a variable answers two questions: (a) how long does
the variable exist? and (b) from where in our code can we set or retrieve the vari-
able’s value? For movie clip variables, we have shown the factors involved in answer-
ing the second question. But we skipped answering the first question. Let’s return to
it now with one final variable-coding scenario.
Scenario 4: Life span of movie clip variables
Suppose we create a new movie with keyframes at frames 1, 2, and 3. On frame 1, we
place a clip instance,
ball. On the ball timeline, we create a variable, radius. Assume
frame 3 of our main timeline is a blank keyframe (the
ball instance is not present
there).
From frame 2 of the main movie timeline, we can find out the value of
radius using
this code:
trace(ball.radius);
Here’s the question: if we move this line of code from frame 2 to frame 3 of the main
timeline, what appears in the Output window when our movie plays?
Answer:
undefined.