Example: Writing custom classes 265
This code declares the same variable inside an inner block.
■ Do not assign many variables to a single value in a statement, because it is difficult to read,
as you can see in the following ActionScript code samples:
// bad form
xPos = yPos = 15;
or
// bad form
class User {
private var m_username:String, m_password:String;
}
■ Have a good reason for making public instance variables, or public static, class, or member
variables. Make sure that these variables are explicitly public before you create them
this way.
■ Set most member variables to private unless there is a good reason to make them public. It
is much better from a design standpoint to make member variables private and allow
access only to those variables through a small group of getter and setter functions.
About naming class files
Class names must be identifiers—that is, the first character must be a letter, underscore (_), or
dollar sign (
$), and each subsequent character must be a letter, number, underscore, or dollar
sign. As a preferred practice, try to always limit class names to letters.
The class name must exactly match the name of the ActionScript file that contains it,
including capitalization. In the following example, if you create a class called Rock, the
ActionScript file that contains the class definition must be named Rock.as:
// In file Rock.as
class Rock {
// Rock class body
}
You name and create a class definition in the following section. See the section “Creating and
packaging your class files” on page 266 to create, name, and package the class files. For more
information on naming class files, see “Naming classes and objects” on page 739.