ActionScript coding conventions
753
■
Don’t
overuse
getter/setter functions in your class file.
Getter/setter functions are excellent for a variety of purposes (see
“About getter and setter
methods” on page 255
), however overuse might indicate that you could improve upon
your application’s architecture or organization.
■
Set most member variables to private unless you have a good reason for making them
public.
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.
Using the this prefix in class files
Use the
this
keyword as a prefix within your classes for methods and member variables.
Although it is not necessary, it makes it easy to tell that a property or method belongs to a
class when it has a prefix; without it, you cannot tell if the property or method belongs to the
superclass.
You can also use a class name prefix for static variables and methods, even within a class. This
helps qualify the references you make. Qualifying references makes for readable code.
Depending on what coding environment you are using, your prefixes might also trigger code
completion and hinting. The following code demonstrates prefixing a static property with a
class name:
class Widget {
public static var widgetCount:Number = 0;
public function Widget() {
Widget.widg+;
}
}
NO
T
E
You don’t have to add these prefixes, and some developers feel it is unnecessary.
Macromedia recommends that you add the
this
keyword as a prefix, because it can
improve readability and it helps you write clean code by providing context.
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...