Scope of a Variable

   

The first time you assign information to a variable is known as "initializing" the variable. To initialize a variable in Normal mode, you use the command set variable . This command adds value to a variable. In Expert mode, you simply type out your statement. When scripting an initialization, be sure that your variable is to the left, followed by an equal sign, and then the value of the variable to the right:

 mySize=150; 

Once you've initialized a variable, it belongs in the Timeline you create it in. This is the scope of the variablethe location where your variable has some meaning and can now be used. Think of a variable's scope as its location. For example, using the example script above, if you initialize a variable within myMovieClip , then the variable is scoped to that movie clip.

To have access to a variable anytime or anywhere within your Flash movie, you can initialize a global variable. The beauty of a global variable is that it is scoped to all Timelines throughout your document. You can call a global variable anytime simply by referencing its name. To create a global variable, you precede the variable name with the identifier _global. For example:

 _global.weightFactor=100 

Once the weight factor has been identified as a global variable, you can call its contents at any point in the Flash document.

TIP

You can also modify the contents of a global variable. To do so, simply use the _ global identifier with the variable name, and then define its new value.



   
Top


Certified Macromedia Flash MX Designer Study Guide
Certified Macromedia Flash MX Designer Study Guide
ISBN: 0321126955
EAN: 2147483647
Year: 2001
Pages: 142

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