766 Best Practices and Coding Conventions for ActionScript 2.0
■ Use spaces to separate all operators and their operands.
Using spaces makes it is easier to distinguish between method calls and keywords, as the
following example shows:
//good
var sum:Number = 7 + 3;
//bad
var sum:Number=7+3;
An exception to this guideline is the dot (.) operator.
■ Don’t include a space between unary operators and their operands.
For example, increment (++) and decrement(--), as shown in the following example:
while (d++ = s++)
-2, -1, 0
■ Don’t include spaces after an opening parenthesis and before a closing parenthesis.
The following ActionScript code shows an example of this:
//bad
( "size is " + foo + "\n" );
//good
("size is " + foo + "\n");
■ Put each statement on a separate line to increase the readability of your ActionScript
code.
The following ActionScript code shows an example of this:
theNum++; // Correct
theOtherNum++; // Correct
aNum++; anOtherNum++; // Incorrect
■ Don’t embed assignments.
Embedded statements are sometimes used to improve performance in a SWF file at
runtime, but the code is much harder to read and debug. The following ActionScript code
shows an example of this (but remember to avoid single-character naming in the
actual code):
var myNum:Number = (a = b + c) + d;
■ Assign variables as separate statements.
The following ActionScript code shows an example of this (but remember to avoid single-
character naming in the actual code):
var a:Number = b + c;
var myNum:Number = a + d;
■ Break a line before an operator.
■ Break a line after a comma.