752
Best Practices and Coding Conventions for ActionScript 2.0
Guidelines for creating a class
Remember the following guidelines when you create a class file:
■
Place only one declaration per line.
■
Don’t place multiple declarations on a single line.
For example, format your declarations as shown in the following example:
var prodSkuNum:Number; // Product SKU (identifying) number
var prodQuantityNum:Number; // Quantity of product
This example shows better form than putting both declarations on a single line. Place
these declarations at the beginning of a block of code.
■
Initialize local variables when they are declared.
A class’s properties should only be initialized in the declaration if the initializer is a
compile-time constant.
■
Declare variables before you first use them.
This includes loops.
■
Avoid using local declarations that hide higher-level declarations.
For example, don’t declare a variable twice, as the following example shows:
var counterNum:Number = 0;
function myMethod() {
for (var counterNum:Number = 0; counterNum<=4; cou+) {
// statements;
}
}
This code declares the same variable inside an inner block, which is a practice to avoid.
■
Don’t assign many variables to a single value in a statement.
Follow this convention because otherwise your code is difficult to read, as the following
ActionScript code shows:
playBtn.onRelease = playBtn.onRollOut = playsound;
or
class User {
private var m_username:String, m_password:String;
}
■
Make a method or property public only if it needs to be public for a reason. Otherwise,
make your methods and properties private.
Содержание 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...