Creating an Invisible Variable

I l @ ve RuBoard

In the preceding exercise, you set up variables when you created special types of text boxes. These text boxes make the contents of the variable visible, both to you (the Flash author) and the viewers of your movie. You might think of a variable that has no associated text box as being an invisible variable, because neither you nor your target audience will ever see the contents of the variable directly (although as the author, you will see the variable within the script). To create a variable that has no representation on the Stagea process called declaring a variable you can use the set variable action.

Instead of directing your script to put the result of your mathematical calculations in the Lucky Number text box, you can put the results in an invisible variable where you might perform several calculations before outputting the result.

To declare a new invisible variable:

  1. Continuing with the file you created in the preceding exercise, select the button instance on the Stage.

  2. In the Actions-Button panel, select Line 1 in the Script pane.

  3. From the Add menu, choose Actions > Variables > set variable .

    Flash updates the Script pane to look like Figure 15.13. The highlighted words <not set yet> indicate that you must name the variable.

    Figure 15.13. To create a variable without a text box, use the set variable action, and fill in the variable name and value.

    graphics/15fig13.gif

  4. With Line 2 selected in the Script pane, in the Variable field, enter the variable name holdStuffVAR .

    This field tells Flash to put the value that you are about to enter in a variable that exists only in the electronic world of Flash.

  5. Check the Expression checkbox to the right of the Value field.

    Flash highlights the placeholder <not set yet> in the Value field and in the Script pane (Figure 15.14).

    Figure 15.14. When you set the value of your variable to be an expression by checking the Expression checkbox, Flash warns you that you still need to enter the formula for the value by highlighting the placeholder text <not set yet> in the Script pane.

    graphics/15fig14.gif

  6. In the Value field, enter Number (ageVAR) + 2 .

  7. In the Script pane, select Line 3.

  8. In the Value field, enter holdStuffVAR * 2 .

    This line of the script instructs Flash to take the contents of your invisible variable and multiply it by 2. Your script should look like Figure 15.15. Now you're ready to see the script at work.

    Figure 15.15. This script places the result of your first calculation (adding 2 to the number entered in the Age text box) into an invisible containerthe variable named holdStuffVAR. Then Flash multiplies that number by 2 and places the result in the Lucky Number text box.

    graphics/15fig15.gif

  9. From the Control menu, choose Test Movie to try out your variable-manipulation script.

  10. Type a number in the Age text box.

  11. Click the button.

    Flash adds 2 to the number you entered, temporarily stores the resulting number in the invisible variable, multiplies that number by 2, and places that result in the Lucky Number text box.

graphics/01icon02.gif Tip

  • You don't actually have to use the set variable action to create a new invisible variable. Simply entering a name and using the assignment operator ( otherwise known as an equals sign) is enough to let Flash know that you are setting up a variable.


I l @ ve RuBoard


Macromedia Flash MX for Windows and Macintosh. Visual QuickStart Guide
Macromedia Flash MX 2004 for Windows and Macintosh (Visual QuickStart Guides)
ISBN: 0582851165
EAN: 2147483647
Year: 2002
Pages: 243

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net