EasyManua.ls Logo

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

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...
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.
Dont 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 classs 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, dont 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.
Dont 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.

Table of Contents

Related product manuals