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.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...