var x = 10;
In the above example 'x' is the name of the variable and 10 is the value of the variable. You always need to initialize the variable before it is using.
Variable Names
A variable name must be a valid identifier. Also it cannot be any special words like true, false, null, undefined. Also a variable name must be unique with in the scope. You should not use any ActionScript element as the variable name.
Variable Scope
A variable scope determines the lifetime of the variables. It also determines the visibility or what all variables are available to the other parts of the program. ActionScript is having three types of variable scopes.
Local variables: - Local variables are declared with in a function or inside a loop. It will be visible only inside the function where it is declared. A local variable is declared by using the keyword var. The local variables expires once we completed the execution of the function. For eg:
function sayHello() {
var siteName="www.CGShelf.com";
}
Timeline variables:- Timeline variables are variables that are available to the script on that timeline. In order to declare a timeline variable we just need to initialize the variable in a frame.
Global variables:- Global variables are having a global scope. It will be available to the entire document. To declare a global variable we use '_global' syntax. For eg:
_global. SiteName ="www.CGShelf.com";
If you have a local variable with the same name of global variable with in a single scope, always the local variable would take the precedence.
discuss this topic to forum
