Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Best Practices and Coding Conventions for ActionScript 2.0 > ActionScript coding conventions > Handling scope > Using the this keyword | |||
Whenever possible, use the this keyword as a prefix instead of omitting the keyword, even if your code works without it. Use the this keyword to learn when a method or property belongs to a particular class. For example, for a function on a timeline, you write ActionScript 2.0 code by using the following format:
circleClip.onPress = function() {
this.startDrag();
};
circleClip.onRelease = function() {
this.stopDrag();
};
For a class, use the following format to write code:
class User {
private var username:String;
private var password:String;
function User(username:String, password:String) {
this.username = username;
this.password = password;
}
public function get username():String {
return this.username;
}
public function set username(username:String):Void {
this.username = username;
}
}
If you consistently add the this keyword in these situations, your ActionScript 2.0 code will be much easier to read and understand.
|
|
|
|