Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Data and Data Types > About variables > About variables and scope > Timeline variables | |||
Timeline variables are available to any script on that particular timeline. To declare timeline variables, use the var statement and initialize them in any frame in the timeline. The variable is available to that frame and all following frames, as shown in the following example.
var myNum:Number = 15; /* initialized in Frame 1, so it's available to all frames */
trace(myNum);
The value 15 appears in the Output panel after approximately a second. Because Flash documents loop by default, the value 15 continually traces in the Output panel every time the playhead reaches Frame 20 in the Timeline. To stop the looping action, add stop(); after the trace() statement.
You must declare a timeline variable before trying to access it in a script. For example, if you put the code var myNum:Number = 15; in Frame 20, any scripts attached to a frame before Frame 20 cannot access myNum and are undefined instead of containing the value 15.
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000664.html
Comments
Varactor said on Dec 5, 2007 at 4:05 AM :