754 Best Practices and Coding Conventions for ActionScript 2.0
About initialization
For the initial values for variables, assign a default value or allow the value of undefined, as
the following class example shows. When you initialize properties inline, the expression on the
right side of an assignment must be a compile-time constant. That is, the expression cannot
refer to anything that is set or defined at runtime. Compile-time constants include string
literals, numbers, Boolean values, null, and undefined, as well as constructor functions for the
following top-level classes: Array, Boolean, Number, Object, and String. This class sets the
initial values of
m_username and m_password to empty strings:
class User {
private var m_username:String = "";
private var m_password:String = "";
function User(username:String, password:String) {
this.m_username = username;
this.m_password = password;
}
}
Delete variables or make variables null when you no longer need them. Setting variables to
null can still enhance performance. This process is commonly called garbage collection.
Deleting variables helps optimize memory use during runtime, because unneeded assets are
removed from the SWF file. It is better to delete variables than to set them to
null. For more
information on performance, see “Optimizing your code” on page 763.
For information on naming variables, see “Naming variables” on page 736. For more
information on deleting objects, see delete statement in ActionScript 2.0 Language
Reference.
NOTE
Flash Player 8 has made improvements in garbage collection within Flash Player.