Formatting ActionScript syntax
767
■
Align the second line with the start of the expression on the previous line of code.
Writing conditional statements
Use the following guidelines when you write conditional statements:
■
Place conditions on separate lines in
if
,
else..if
, and
if..else
statements.
■
Use braces (
{}
) for
if
statements.
■
Format braces as shown in the following examples:
// if statement
if (condition) {
// statements
}
// if..else statement
if (condition) {
// statements
} else {
// statements
}
// else..if statement
if (condition) {
// statements
} else if (condition) {
// statements
} else {
// statements
}
When you write complex conditions, it is good form to use parentheses [()] to group
conditions. If you don’t use parentheses, you (or others working with your ActionScript 2.0
code) might run into operator precedence errors.
For example, the following code does not use parentheses around the conditions:
if (fruit == apple && veggie == leek) {}
The following code uses good form by adding parentheses around conditions:
if ((fruit == apple) && (veggie == leek)) {}
NO
TE
You can control auto-indentation and indentation settings by selecting Edit >
Preferences (Windows) or Flash > Preferences (Macintosh), and then selecting the
ActionScript tab.
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...