4.5 The Timeline

Flash's timeline controls both
animation and the order in which events occur in the movie. Flash MX
and Flash 2004 use the timeline metaphor, although the latter offers
timeline effects to simplify common interactions
with the timeline for repetitive tasks. Furthermore, Flash Pro offers
a screen-based metaphor that helps disguise the underlying timeline
for programmers coming from Visual Basic and similar environments. If
you are a programmer unfamiliar with the timeline, you can imagine it
as a piece of audio tape. When a musician records a song, the various
instruments are recorded on different tracks. The guitar might be on
one track, the drums on another, the lead vocals on another, and
backing vocals on yet another. There might be many separate tracks of
music, but as the tape head glides across the final tape, all tracks
are played together, making one cohesive collage of sound.

This is similar to how the Flash timeline works, only the tracks are
called layers, and each layer can contain audio,
video, animation, or ActionScript code. Also, playback is not
continuous like an audio tape, but more like a motion picture, with
individual frames that the playback head displays at a typical rate
of 10 to 30 frames per second.

That said, a Flash application that acts as an interface to a dynamic
web application might not follow these general principles. The movie
might have a static interface with several screens that can be
displayed. In these cases, the timeline can be used to break up
individual screens of the user interface. Each screen can occupy a
frame or several frames in the movie and can be displayed in response
to a triggering event.

To give you an example, let's say you have an
interface with six main screens: user login, display data, drill down
to a detail of the data, update the data, insert new data, and delete
the data. Each of these six screens of user interface can each occupy
several frames on the timeline with specific starting and ending
points. As a particular screen is needed, the playback head can be
sent to the starting point on the timeline that begins that
particular element, and it will stop at the end of that section. In
effect, you have six individual scenes that are meant to be played
individually rather than sequentially.

How does the timeline fit into Flash Remoting? Well, the short answer
is that it doesn't. All of your Flash Remoting code
can be placed into frame 1 of the main timeline (or the first frame
following any preloader) so that it executes and initializes when the
movie loads. Your remote methods will be available to all other parts
of your movie if you do this.

You can place a stop( ) function in the code to
make sure that the movie doesn't begin playing until
all of the Flash Remoting initialization code has executed. Your
methods and event handlers can all be contained in one central
location on one layer in one frame of the timeline. This
isn't always necessary or even possible, but it is a
goal to shoot for when developing your Flash Remoting application.

If all of your code is self-contained, you can put it into an
external .as file and use an
#include directive to incorporate it in your Flash
movie.