User Guide

Behaviors conventions 105
Behaviors conventions
Behaviors are prewritten code snippets that can be instantly added to parts of a FLA file. The
introduction of behaviors has added to the complexity of determining best practices in Flash,
because the way some behaviors are added does not follow typical and ideal workflows. Many
developers usually enter ActionScript either into one or several frames on the main Timeline or in
external ActionScript files, which is a good practice to follow. However, when you use behaviors,
sometimes code is placed directly on symbol instances (such as buttons, movie clips, or
components) instead of being placed on the Timeline.
Behaviors are convenient, save substantial time, and can be useful for novice Flash and
ActionScript users. Before you start using behaviors, take a close look at how you want to
structure your FLA file:
What behaviors do you need for your project?
What code do the behaviors contain?
How are you are going to use and implement behaviors?
What other ActionScript do you need to add?
If you carefully plan a document that uses behaviors, you can avoid problems that could be
created by decentralizing your ActionScript.
For more information, see the following topics:
“Comparing timeline code with object code” on page 105
“Using behaviors” on page 106
“Being consistent” on page 107
“Being courteous” on page 107
Comparing timeline code with object code
Planning a project and organizing a document or application cannot be underestimated,
particularly when you are creating large involved projects or working in teams. This is why the
placement of ActionScript—often what makes the project work—is important.
Many developers do not place ActionScript on symbol instances, and instead place their code on
the Timeline (timeline code) or in classes. Because Behaviors add code to many locations in a FLA
file, it means that your ActionScript is not centralized and can be difficult to locate. When code is
not centralized, it is difficult to figure out interactions between the snippets of code, and it is
impossible to write code in an elegant way. It can potentially lead to problems debugging code or
editing files. Many developers also avoid placing code on different frames on the Timeline or
avoid placing timeline code inside multiple movie clips where it is hidden. By placing all your
code, including functions that must be defined before they are used, in a SWF file, you can avoid
such problems.
Flash has features that make it easy to work with behaviors in a document and with decentralized
ActionScript. If you use behaviors, try the following features when working on your project:
Script navigator Makes your timeline code or code on individual objects easy to find and edit
in the Actions panel.