About naming variables

Be careful when you start naming variables, because although they can have nearly any name, there are some rules. A variable's name must follow these rules:

If you don't 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

The ActionScript editor supports code hints for built-in classes and for variables that are based on these classes. If you want Flash to provide code hints for a particular object type that you assign to a variable, you can strictly type the variable. Code hints provide tooltip-style syntax hints and a pop-up menu that helps you write your code quickly.

For example, type the following code:

var members:Array = new Array();
members.

As soon as you type the period (.) in the Actions panel, Flash displays a list of methods and properties available for Array objects.

For recommended coding conventions for naming variables, see Naming variables.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000659.html