| 1. Open a new flash document and save it as
variables.fla. 2. Counting Up!
Name layer 1 count up. Click on
frame 1 of layer Coutup. Open your action panel. We will declare a variable
called countup. If countup is set to 1, We can simply increase countup in
increments of 1 by typing in countup = countup +1. This can be shortened to countup ++;
To test the Variable Add a Text box on a new layer called text. Set the text box from static text to
dynamic text so it imports a variable. Set the variable name to countup.
Play your movie. The number stops at 1. Click in frame 2 and hit your F5
key. Now play your movie. You can watch the variable change because the
movie plays repeatedly.

You can stop the counting if you put a stop on the frame. We can limit
the counting also by setting an if statement in the action script. We want
to say that if countup is greater then or equal to 60, set countup to 0,
then add 1. that would appear like below. Now play your movie.
3. Counting down Add a layer and call it count down.
Open your action panel and set countdown --. This will cause the variable
countdown to decrease by increments of 1.
We can not tell what the variable is without a test of some sort so we can
add to the text layer another text box, with dynamic text and the variable
called countdown. When you test this, you will see the numbers will drop
down below zero. Once again, you can limit your number range by putting in
an if statement. If I want to limit the numbers between 60 and 0, like the
count up, I can say "if countdown is less then or equal to 0, make countdown
equal to 60. then reduce countdown by 1.
Test your movie. 4.
Changing the variable name Often you find it necessary to call
up different variable names in a pattern or randomly. While random will be
covered in a different tutorial, here we will set up a script to change a
variable name in increments, such as bulb1, bulb2, bulb3, etc. We can name
the variable as a function of another variable, in this case it would be a
function of the variable countup. Insert a layer and call it variable
countup. Insert a keyframe in frame 1. Open up the Actions panel. We
will declare a value for the new variable, bulb. We will set the variable
bulb to equal the number that countup is, or bulb = ["bulb" +
countup];
To
check for this value, we can put another dynamic text box in our movie
that has the variable of bulb. Insert a dynamic text box with the
variable bulb. Test your movie. We can do the same thing for
changing the variable number by decreasing increments if we use the
variable countdown. Insert a new layer and call it variable countdown.
Insert the script to change the variable light. This script will look like
this if the new variable is light:
You
can display the value for the light variable in a text box if it is a
dynamic text box with a variable of light. 5. Boolean True
or False The True and false criteria in flash is a true Boolean. It
can be represented as 0 or 1. To get a true false statement to work, you can
actually test a mathematical statement. in this case, we will test the
statement: if countup equals 30 and return a true result if it is true.,
otherwise it is false. The script on the new true/false layer is as
follows:
Make sure you name your dynamic text box answer. |