EasyManua.ls Logo

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

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...
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.
Dont 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
Dont 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
Dont 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.

Table of Contents

Related product manuals