Organizing code for screens

There are three places you can place code in a screen-based application:

Because code can be placed in many different locations, it complicates matters as to where you should put your code. Therefore, you must consider the type of application you're writing and what it requires in the way of ActionScript. As with behaviors, you should use ActionScript consistently in screen-based applications.

The difference between screens and behaviors is that the ActionScript that behaviors add is much more complex than most of the behaviors available for a regular FLA file. Screens are based on complex ActionScript, so some of the code used for transitions and changing slides might be difficult to write yourself.

You might use either behaviors or ActionScript that attaches directly to screens, combined with either a Timeline or an external ActionScript file. Even if you decentralize your code this way, have code put on screens and an external ActionScript file, you should still avoid attaching code directly to movie clip or button instances that are placed on individual screens. This ActionScript is still hard to locate in a FLA file, debug, and edit.

Even if you attach code directly to a screen, it is more acceptable and easier to use than in regular FLA files for the following reasons:

If you use behaviors placed on screens (or other instances), remember to document the location on Frame 1 of the main Timeline. This is particularly important if you also place ActionScript on the Timeline. The following code is an example of the comment you might want to add to your FLA file:

/*
   On Frame 1 of main Timeline.
   ActionScript is placed on individual screens and directly on instances in addition to the code on the Timeline (frame 1 of root screen).
  ...
*/

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00000861.html