EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 91

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About variables 91
When you assign a value, you use an operator to define a value to a variable. For example, the
following script uses the assignment operator to assign a value of 7 to the variable
numChildren:
var numChildren:Number = 7;
If you want to change the value of the numChildren variable, use the following code:
numChildren = 8;
For more information on using operators in your ActionScript, see About operators
on page 176.
About naming variables
Be careful when you start naming variables, because although they can have nearly any name,
there are some rules. A variables name must follow these rules:
A variable must be an identifier.
A variable cannot be a keyword or an ActionScript literal such as true, false, null, or
undefined. For more information on literals, see About literals” on page 130.
A variable must be unique within its scope (see About variables and scope” on page 96).
A variable should not be any element in the ActionScript language, such as a class name.
If you dont follow the rules when you name a variable, you might experience syntax errors or
unexpected results. In the following example, if you name a variable
new and then test your
document, Flash will generate a compiler error:
// This code works as expected.
var helloStr:String = new String();
trace(helloStr.length); // 0
// But if you give a variable the same name as a built-in class...
var new:String = "hello"; //error: Identifier expected
var helloStr:String = new String();
trace(helloStr.length); // undefined
NOTE
You don’t need to use var because the variable has previously been defined.
NOTE
An identifier is the name of a variable, property, object, function, or method. The first
character of an indentifier must be a letter, underscore (_), or dollar sign ($). Each
subsequent character can be a number, letter, underscore, or dollar sign.

Table of Contents

Related product manuals