Controlling the Timeline with ActionScript


One of the simplest things to do with ActionScript is to control the timeline. With ActionScript, you can send the playback head to any frame in the timeline. You can choose a numbered frame, or give that frame a label; however, using frame labels is more flexible than using numbered frames to control the timeline with ActionScript. With frame labels, you don't have to rewrite all your coding every time you reorganize the timeline.

To create a labeled frame, make a new top layer in your project. Place it above your actions layer so that you can easily spot your frame labels. Then insert a blank keyframe. Give the frame a name in the in the <Frame Label> field of the Property inspector. Figure 11.1 shows a frame on the timeline labeled as start.

Figure 11.1. A frame label attached to a blank keyframe in its own layer.


To control the timeline you can use one of the global functions that are built in to Flash. These functions are all commonly used commands that are listed in the actions listings from the upper-left corner of the Actions panel (see Figure 11.2).

Figure 11.2. Accessing the list of global functions for controlling the timeline.


To stop the playback head on a frame, you can use the stop() action attached to a blank keyframe at the location on the timeline where you want to stop.

stop();


The playback head reads the action on this frame and then stops.

To send the play head to a specific frame, you can use the gotoAndPlay() function. For example, use the gotoAndPlay() function to send the playhead back to the start frame label in the first frame, creating an animation that loops continuously.

gotoAndPlay("start");


The entry inside the parentheses of this method is the data that the playback head uses to know where to jump on the timeline. This can be either a frame number or a frame label name. The word "start" is in quotes to tell the playback head to go to a frame label with that name.



Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net