User Guide

82 Chapter 3: Using Best Practices
Use line breaks to make complex statements easier to read You can format some
statements, such as conditional statements, in several ways. Sometimes, formatting statements
across several lines rather than a single line makes it easier to read. For more information on
properly formatting statements, see “Writing syntax and statements” on page 89.
Use consistent indentation in your code Indenting helps show the hierarchy of the codes
structure. Use the same indentation throughout your ActionScript, and make sure that you align
the braces (
{}) properly. Aligned braces improve the readability of your code. If your ActionScript
syntax is correct, Flash automatically indents the code correctly when you press Enter (Windows)
or Return (Macintosh). You can also press the Auto Format button in the Actions panel to indent
your ActionScript if the syntax is correct.
Note: You can control autoindentation and indentation settings by selecting Edit > Preferences, and
then selecting the ActionScript tab.
ActionScript coding standards
One of the most important aspects about programming is consistency, whether it relates to
variable naming schemes, coding standards, or where you place your ActionScript code. Code
debugging and maintenance is dramatically simplified if the code is organized and adheres to
standards. Formatted code that follows an established set of guidelines is easier to maintain, and
easier for other developers to understand and modify.
For more information, see the following topics:
“Organizing ActionScript in a document” on page 82
“Writing ActionScript” on page 85
“Using scope” on page 95
“Using functions” on page 98
Organizing ActionScript in a document
It is important to understand where to put your ActionScript: Should it be in the FLA file, should
it be put on the server in an external AS file, or should it be a class written using ActionScript 2.0?
The first thing you must understand is how to structure your project. If you are building an
application, read “Building Flash Applications” on page 121.
A general guideline is to put all your code in as few places as possible, whether you put it inside a
FLA document or in external files. For information on choosing between ActionScript 1 or
ActionScript 2.0, see “Choosing between ActionScript 1 and ActionScript 2.0” on page 84.
Organizing your code helps you edit projects more efficiently, because you can avoid searching in
different places when you debug or modify the ActionScript. The following sections provide more
information about where to put your ActionScript.