EasyManua.ls Logo

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

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...
736 Best Practices and Coding Conventions for ActionScript 2.0
Naming variables
Variable names can only contain letters, numbers, and dollar signs ($). Do not begin variable
names with numbers. Variables must be unique and they are case-sensitive in Flash Player 7
and later. For example, avoid the following variable names:
my/warthog = true; // includes a slash
my warthogs = true; // includes a space
my.warthogs = true; // includes a dot
5warthogs = 55; // begins with a number
Use strict data typing with your variables whenever possible because it helps you in the
following ways:
Adds code completion functionality, which speeds up coding.
Generates errors in the Output panel so you dont have a silent failure when you compile
your SWF file. These errors help you find and fix problems in your applications.
To add a data type to your variables, you must define the variable using the
var keyword. In
the following example, when creating a LoadVars object, you would use strict data typing:
var paramsLv:LoadVars = new LoadVars();
Strict data typing provides you with code completion, and ensures that the value of paramsLv
contains a LoadVars object. It also ensures that the LoadVars object will not be used to store
numeric or string data. Because strict typing relies on the
var keyword, you cannot add strict
data typing to global variables or properties within an object or array. For more information
on strict typing variables, see About assigning data types and strict data typing” on page 81.
Use the following guidelines when you name variables in your code:
All variables must have unique names.
Dont use the same variable name with different cases.
Dont use, for example,
firstname and firstName as different variables in your
application. Although names are case-sensitive in Flash Player 7 and later, using the same
variable name with a different case can be confusing to programmers reading your code
and can cause problems in earlier versions of Flash that do not force case sensitivity.
Dont use words that are part of the ActionScript 1.0 or 2.0 language as variable names.
In particular, never use keywords as instance names, because they cause errors in your
code. Dont rely on case sensitivity to avoid conflicts and get your code to work.
NOTE
Strict data typing does not slow down a SWF file. Type checking occurs at compile time
(when the SWF file is created), not at runtime.

Table of Contents

Related product manuals