100 Using Symbols, Instances, and Library Assets
You need to decide when you need to use behaviors instead of writing ActionScript. First,
answer the questions in the introductory section “Best practices for using behaviors”
on page 98. Examine how and where you want to use behaviors and ActionScript in your FLA
file. Then, consider the following questions:
■ Do you have to modify the behavior code? If so, by how much?
■ Do you have to interact with the behavior code with other ActionScript?
■ How many behaviors do you have to use, and where do you plan to put them in the FLA
file?
Your answers to these questions determine whether you should use behaviors. If you want to
modify the behavior code to any extent, do not use behaviors. Behaviors usually cannot be
edited using the Behaviors panel if you make modifications to the ActionScript. And if you
plan to significantly edit the behaviors in the Actions panel, it is usually easier to write all of
the ActionScript yourself in a centralized location. Debugging and modifications are easier to
make from a central location than having code generated by behaviors placed in many areas
around your FLA file. Debugging and interaction can be inelegant or difficult with scattered
code, and sometimes it is easier to write the ActionScript yourself.
The main difference between a FLA file with behaviors and a FLA file without behaviors is
the workflow you must use for editing the project. If you use behaviors, you must select each
instance on the Stage, or select the Stage, and open the Actions or Behaviors panel to make
modifications. If you write your own ActionScript and put all your code on the main
Timeline, you only have to go to the Timeline to make your changes.
Use behaviors consistently throughout a document when they are your main or only source of
ActionScript. It is best to use behaviors when you have little or no additional code in the FLA
file, or have a consistent system in place for managing the behaviors that you use.
Being consistent
There are some guidelines for using behaviors; the main thing is consistency. If you add
ActionScript to a FLA file, put code in the same locations where behaviors are added, and
document how and where you add code.
For example, if you place code on instances on the Stage, on the main Timeline, and in class
files, you should examine your file structure. Your project will be difficult to manage, because
the code placement is inconsistent. However, if you logically use behaviors and structure your
code to work in a particular way surrounding those behaviors (place everything on object
instances), your workflow is logical and consistent. The document will be easier to modify
later.