Naming conventions
737
■
Don’t use variables that are parts of common programming constructs.
Don’t use language constructs if you are aware of them in other programming languages,
even if Flash does not include or support these language constructs. For example, do not
use the following keywords as variables:
textfield = "myTextField";
switch = true;
new = "funk";
■
Always add data type annotations to your code.
Also referred to as “using strict data types with your variables,” or “strong typing your
variables,” adding type annotations to your variables is important in order to:
■
Generate errors at compile time so your application doesn’t silently fail.
■
Trigger code completion.
■
Helps users understand your code.
For information on adding type annotations, see
“About assigning data types and strict
data typing” on page 81
.
■
Don’t overuse the Object type.
Data type annotations should be precise to improve performance. Use an Object type
only when there is no reasonable alternative.
■
Keep variables as short as possible while retaining clarity.
Make sure your variable names are descriptive, but don’t go overboard and use overly
complex and long names.
■
Only use single-character variable names for optimization in loops.
Optionally, you can use single-character variables for temporary variables in loops (such as
i
,
j
,
k
,
m
, and
n
). Use these single-character variable names only for short loop indexes, or
when performance optimization and speed are critical. The following example shows this
usage:
var fontArr:Array = TextField.getFontList();
fontArr.sort();
var i:Number;
for (i = 0; i<fontArr.length; i++) {
trace(fontArr[i]);
}
■
Start variables with a lowercase letter.
Names with capital first letters are reserved for classes, interfaces, and so on.
■
Use mixed case for concatenated words.
For example, use
myFont
instead of
myfont
.
Содержание 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...