beautypg.com

Best practices - behaviors conventions – Adobe Flash Professional CC 2014 v.13.0 User Manual

Page 854

background image

Best practices - Behaviors conventions

To the top

To the top

To the top

To the top

About behaviors conventions
Comparing timeline code with object code
When to use behaviors
Using behaviors consistently
Sharing files that use behaviors

About behaviors conventions

Behaviors are prewritten ActionScript 2.0 code that you can add to parts of a FLA file. Many developers enter ActionScript code either into one or
several frames on the main Timeline or in external ActionScript files. 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 not supported by ActionScript 3.0.

Comparing timeline code with object code

To avoid problems that decentralized ActionScript 2.0 code creates, carefully plan a document that uses behaviors. 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, your ActionScript is not centralized and can be difficult to locate. When code is not centralized, it is difficult to understand
interactions between the snippets of code, and it is impossible to write elegant code. Decentralized code can potentially lead to problems
debugging code or editing files.

If you use behaviors, try the following features to facilitate working with behaviors and decentralized ActionScript:

Script Navigator Makes your timeline code or code on individual objects easy to find and edit in the Actions panel.

Find And Replace Lets you search for strings and replace them in a FLA file.

Script Pinning Lets you pin multiple scripts from various objects and work with them simultaneously in the Actions panel. This method works best
with the Script navigator.

Movie Explorer Lets you view and organize the contents of a FLA file, and select elements (including scripts) for further modification.

When to use behaviors

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 make your changes on the Timeline.

If you have a FLA file with symbols, you can select one of the instances on the Stage, and use the Add menu on the Behaviors panel to add a
behavior to that instance. The behavior you select automatically adds code that attaches to the instance, using “object code” such as the on()
handler. You can also select a frame on a timeline, and add different behaviors to a frame using the Behaviors panel.

Decide how to structure your FLA file. Examine how and where to use behaviors and ActionScript in your FLA file. Consider the following
questions:

What code do the behaviors contain?

Do you have to modify the behavior code? If so, by how much? To modify the behavior code to any extent, do not use behaviors. You
usually cannot edit behaviors by using the Behaviors panel if you make modifications to the ActionScript. To significantly edit the behaviors in
the Actions panel, it is usually easier to write all of the ActionScript yourself in a centralized location.

What other ActionScript do you need, and does other ActionScript have to interact with the behavior code? Debugging and modifications are
easier to make from a central location. For example, if code on a timeline interacts with behaviors placed on objects, avoid behaviors.

How many behaviors do you have to use, and where do you plan to put them in the FLA file? If your behaviors are all placed on a timeline,
they might work well in your document. Or, your workflow might not be affected if you use only a small number of behaviors. However, if you
use many behaviors on a lot of object instances, writing your own code on the Timeline or in external ActionScript files might be more
efficient.

Remember, ActionScript 3.0 does not support behaviors.

Using behaviors consistently

847