
420
USING FLASH CS4 PROFESSIONAL
Best practices
Important:
If you select Save when working with a document, you can undo before that save point. Because Save and
Compact deletes the earlier version of the file and replaces it with the optimized version, you cannot undo earlier
changes.
If you are not using version control software to create backups of your FLA file, use Save As and type a new file
name for your document after every milestone in your project.
Many software packages allow users to use version control with their files, which enables teams to work efficiently
and reduce errors (such as overwriting files or working on old versions of a document). As with other documents,
you can use these programs to organize the Flash documents outside Flash.
Organizing ActionScript in an application
Keeping actions together
Whenever possible, put your ActionScript® in a single location. Organizing your code in one place helps you edit
projects more efficiently, because you can avoid searching in different places when you debug or modify the
ActionScript. If you put code in a FLA file, put ActionScript on Frame 1 or Frame 2 in a layer called
actions
on the
topmost layer in the Timeline. Alternatively, you might put all of your code in ActionScript files. Some Flash
applications do not always put all code in a single place (in particular, ActionScript 2.0-based applications that use
screens or behaviors).
You can usually put all your code in the same location (on a frame, or in ActionScript files), with the following
advantages:
•
Code is easy to find in a potentially complex source file.
•
Code is easy to debug.
See also
“
Attaching code to objects
” on page 420
“
Behaviors conventions
” on page 421
“
Using the MVC design pattern
” on page 428
“
Organizing files and storing code
” on page 428
Attaching code to objects
Avoid attaching ActionScript to objects in a FLA file, even in simple SWF files. (Only ActionScript 1.0 and 2.0. can be
attached to objects; ActionScript 3.0 cannot.) Attaching code to an object means that you select a movie clip,
component, or button instance; open the Actions panel; and add ActionScript using the
on()
or
onClipEvent()
handler functions.
Attaching ActionScript code to objects is strongly discouraged for the following reasons:
•
It is difficult to locate, and the FLA files are difficult to edit.
•
It is difficult to debug.
•
ActionScript that is written on the timeline or in classes is more elegant and easier to build upon.
•
It encourages poor coding style.
Updated 5 March 2009