Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Best Practices and Coding Conventions for ActionScript 2.0 > ActionScript coding conventions > Structuring a class file > Guidelines for creating a class | |||
Remember the following guidelines when you create a class file:
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.
A class's properties should only be initialized in the declaration if the initializer is a compile-time constant.
This includes loops.
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; counterNum++) {
// statements;
}
}
This code declares the same variable inside an inner block, which is a practice to avoid.
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;
}
Getter/setter functions are excellent for a variety of purposes (see About getter and setter methods), however overuse might indicate that you could improve upon your application's architecture or organization.
From a design standpoint, it is much better to make member variables private and allow access to those variables through a group of getter/setter functions only.
|
|
|
|