Instance variables follow static variables. Write the public member variables first, and follow them
with private member variables.
Following the public and private member variables, add the constructor statement, such as the
one in the following example:
public function UserClass(username:String, password:String) {...}
Finally, write your methods. Group methods by their functionality, not by their accessibility or
scope. Organizing methods this way helps improve the readability and clarity of your code. Then
write the getter/setter methods into the class file.
In general, only place one declaration per line, and do not place either the same or different types
of declarations on a single line. Format your declarations as the following example shows:
var prodSKU:Number;
var prodQuantity:Number;
This example shows better form than putting both declarations on a single line. Place these
declarations at the beginning of a block of code enclosed by braces (
Initialize local variables when they are declared, unless that initial value is determined by a
calculation. Declare variables before you first use them, except in
Avoid using local declarations that hide higher level declarations. For example, do not declare a
variable twice, as the following example shows:
var counter:Number = 0;
function myMethod() {
for (var counter = 0; counter<=4; counter++) {
//statements;
}
}
This code declares the same variable inside an inner block, which is a practice you should avoid.
The following example shows the organization of a simple class:
class com.macromedia.users.UserClass {
private var m_username:String;
private var m_password:String;
public function UserClass(username:String, password:String) {
this.m_username = username;
this.m_password = password;
}
public function get username():String {
return this.m_username;
}
public function set username(username:String):Void {
this.m_username = username;
}
public function get password():String {
return this.m_password;
}
public function set password(password:String):Void {
this.m_password = password;
}
}
// product SKU (identifying) number
// quantity of product
).
{}
loops.
for
Using classes and ActionScript 2.0
101
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers