User Guide
General coding conventions 71
switch = true;
new = "funk";
Always strict data type your variables, which helps avoid errors in your code and trigger code
completion. For more information on strict typing and suffixes, see “Using code completion and
suffixes” on page 78. You should use suffixes with your variables because suffixes improve
ActionScript readability.
Try to keep variables as short as possible while retaining clarity. For more information on
processing and performance, see “Performance and Flash Player” on page 114. Some developers
use one character variables for temporary variables (such as
i, j, k, m, and n). Use single characters
only in certain cases, such as the following:
var font_array:Array = TextField.getFontList()
font_array.sort();
for (var i = 0; i<font_array.length; i++) {
trace(font_array[i]);
}
Start variables with a lowercase letter, and use mixed case for concatenated words. If you do not
use mixed case, then consistently use lowercase for all your variables. You can also use underscores
to separate concatenated words. Do not use a combination of these different naming conventions
in a single project.
Some developers use Hungarian notation to indicate the data type. Hungarian notation adds a
prefix before the variable name to identify what data type the variable is. This form of notation is
not recommended as a best practice. However, some developers use it as an alternative to adding
suffixes, so you should be aware of the practice. The following ActionScript uses Hungarian
notation to indicate the String data type:
var strMyName:String = "Rudy"; //indicates string
Use complementary pairs when you create a related set of variable names. For example, you might
use complementary pairs to indicate a minimum and maximum game score:
var minScore:Number = 10; //minimum score
var maxScore:Number = 500; //maximum score
The ActionScript editor and Script pane in the Actions panel have built-in support for code
completion. This means that Flash shows methods and properties for the current object when you
enter ActionScript code. You must name variables in a particular way or use specific commenting
techniques to see code completion menus. The following are the three ways to use code
completion:
• Use strict data typing, which is recommended if you are using ActionScript 2.0.
• Use suffixes, which is recommended if you are using ActionScript 1.
• Use comments, which is recommended only if you do not use suffixes or strict data typing.
For more information on code completion, see “Using code completion and suffixes” on page 78.