Accessibility

TechNote (Archived)

Variable names conflicting with object names

Issue



ActionScript may fail to execute as expected if predefined ActionScript object names are used as variable identifiers.

For example, in the following consecutive lines of ActionScript, the variable named date is declared before a new Date object is created. As a result, the variable now will be undefined when the code is executed.

 date = "July 20th, 1971"; // 'date' contains correct assigned value    now = new Date(); // 'now' will be undefined 

Reason


Use of a variable name that is the same as the name of a predefined ActionScript object causes a name space conflict. As a result, all subsequent calls to the constructor method of the object with that name will not function. A full list of predefined ActionScript objects can be found in the section titled 'Writing Scripts with ActionScript > Using predefined objects' of the ActionScript Reference.

Solution
Using object and variable names specific to the project being coded will help avoid this problem. For example, if the variable date shown in the above example were being used to contain someone's date of birth the variable might be renamed to reflect its use:

 birthDate = "July 20th, 1971"; 

This practice also makes the code more readable.

Solution


Using object and variable names specific to the project being coded will help avoid this problem. For example, if the variable date shown in the above example were being used to contain someone's date of birth the variable might be renamed to reflect its use:

 birthDate = "July 20th, 1971"; 

This practice also makes the code more readable.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_14677

Products Affected: