User Guide
72 Chapter 3: Using Best Practices
Constants
Variables should be lowercase or mixed-case letters; however, constants (variables that do not
change) should be uppercase. Separate words with underscores, as the following ActionScript
shows:
var BASE_URL:String = "http://www.macromedia.com"; //constant
var MAX_WIDTH:Number = 10; //constant
Write static constants in uppercase, and separate words with an underscore. Do not directly code
numerical constants unless the constant is
1, 0, or -1, which you might use in a for loop as a
counter value.
You can use constants for situations in which you need to refer to a property whose value never
changes. This helps you find typographical mistakes in your code that might not be found if you
used literals. It also lets you change the value in a single place.
Functions
Function names start with a lowercase letter. Describe what value is being returned when you
create function names. For example, if you are returning the name of a song title, you might name
the function
getCurrentSong().
Establish a standard for relating similar functions, because ActionScript does not permit
overloading. In the context of Object Oriented Programming (OOP), overloading refers to the
ability to make your functions behave differently depending on what data types are passed into it.
Methods
Name methods as verbs with mixed case for concatenated words, making sure that the first letter
is lowercase. For example, you might name methods in the following ways:
sing();
boogie();
singLoud();
danceFast();
You use verbs for most methods because they perform an operation on an object.
Loops
Loop indexes (such as a
for loop) have standardized naming conventions. A simple index loop
(such as a
for loop or while loop) typically uses i, j, k, m, and n as control variables. Use these
single-character variable names only for short loop indexes, or when performance optimization
and speed are critical.