MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 98

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To use timeline variables in a document:
1.
Create a new Flash document, and name it timelinevar.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
var myNum:Number = 15; /* initialized in Frame 1, so it's available to
all frames */
3.
Select Frame 20 of the Timeline.
4.
Select Insert > Timeline > Blank Keyframe.
5.
With the new keyframe selected, type the following ActionScript into the Actions panel:
trace(myNum);
6.
Select Control > Test Movie to test the new document.
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
after the
trace()
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;
Frame 20 cannot access
Local variables
When you use the
var
you declare a local variable within a function block (also called function definition), it is
defined within the scope of the function block, and expires at the end of the function block.
Therefore, the local variable only exists within that function.
For example, if you declare a variable named
that variable will not be available outside of the function.
function localScope():Void {
var myStr:String = "local";
}
localScope();
trace(myStr); // Undefined, because myStr is not defined globally
98
Data and Data Types
statement.
in Frame 20, any scripts attached to a frame before
and are undefined instead of containing the value
myNum
statement inside a function block, you declare local variables. When
within a function named
myStr
stop();
.
15
,
localScope

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents