Understanding the ActionScript Language > About variables > Variable declaration

 

Variable declaration

To declare Timeline variables, use the set variable action or the assignment (=) operator. Both methods achieve the same results.

To declare local variables, use the var statement inside the body of a function. A local variable is scoped to the block, and expires at the end of the block. A local variable not declared within a block expires at the end of its script.

To declare global variables, use the _global identifier before the variable name. The following example creates the global variable myName:

_global.myName = "George";

To test the value of a variable, use the trace action to send the value to the Output window. For example, trace(hoursWorked) sends the value of the variable hoursWorked to the Output window in test mode. You can also check and set the variable values in the Debugger in test mode. For more information, see Testing a movie.