734
Best Practices and Coding Conventions for ActionScript 2.0
General naming guidelines
This section reviews naming guidelines for writing ActionScript code. Naming conventions
are important for writing logical code. The primary purpose is to improve the readability of
your ActionScript 2.0 code. Remember that all variables must have unique names. Names are
case-sensitive in Flash Player 7 and later. Do not use the same name with a different case,
because this can be confusing to programmers reading your code and can cause problems in
earlier versions of Flash that do not force case sensitivity. Keep the following guidelines in
mind when you name items such as variables, files, and classes in Flash:
■
Limit your use of abbreviations.
Use abbreviations consistently. An abbreviation must clearly stand for only one thing. For
example, the abbreviation “sec” might represent “section” and “second.”
■
Concatenate words to create names.
Use mixed-cases (upper and lower case) when you concatenate words to distinguish
between each word for readability. For example, select
myPelican
rather than
mypelican
.
■
Name a file by describing the process or item, such as
addUser
.
■
Don’t use nondescriptive names for methods or variables.
For example, if you retrieve a piece of data that is the visitor’s user name, you might use
the
getUserName()
method instead of the less descriptive
getData()
method. This
example expresses what is happening rather than how you accomplish it.
■
Keep all names as short as possible.
Remember to keep names descriptive.
The following sections offer more detail on naming items such as variables, classes, packages,
and constants in your code.
Avoiding reserved words or language constructs
When naming instances and variables, avoid using reserved words, which can cause errors in
your code. Reserved words include
keywords
in the ActionScript language.
Also, do not use any word in the ActionScript 2.0 languages (called a
language construct
) as an
instance or variable name. ActionScript constructs include class names, component class
names, method and property names, and interface names.
WARNIN
G
Never use different cases to avoid conflicting with reserved words. For example, naming
an instance of the
textfield
TextField class (which doesn’t conflict with TextField
because Flash is case-sensitive) is a poor coding practice.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...