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:
+; // Correct
theO+; // Correct
aNum++; anO+; // 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.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...