Chapter 10. Managing Playback


By default, a Flash movie begins playback as soon as it loads, playing through the end of the movie, and looping back to the beginning and playing again. Unless you are making a simple animation, you'll probably want to control playback or enable user control. For example, most interactive movies, such as games and business or learning applications, need to stop on the first frame (or the first frame following a preloader). Even for animations and video, you'll often need to provide playback control buttons for the user. Flash has several ActionScript methods for controlling playback, including pausing and starting playback, skipping to different portions of the movie, and advancing the playhead one frame at a time. These include stop( ), gotoAndPlay( ), gotoAndStop( ), nextFrame( ), prevFrame( ), nextScene( ), and prevScene( ). Fortunately, these methods are easy to implement.

To script in Flash, you must understand the relationship between events that occur in the movie and ActionScript statements associated with them. Every script executed in Flash occurs in the same sequence:

  1. An event occurs in the movie (examples include button presses, the playback of frames, movie clips being dragged, keypresses, and loaded data).

  2. An event handler associated with that event is triggered.

  3. The actions or statements enclosed in that event handler are executed.

If a series of actions is enclosed in an event handler, and the corresponding event never occurs, the script is never executed. If an event occurs several times, actions enclosed in the corresponding event handler are executed several times.

Chapter 9 discusses several button-related events and event handlers, including onRelease, onRollOver, and onDragOver. Different Flash objects have different event handlers associated with them. These events are covered along with their objects throughout this book. Movie playback actions, like all other actions in Flash, are triggered by events. To give control to the user, tie playback actions to buttons. To trigger playback actions automatically, you can add scripts to keyframes. Scripts attached to keyframes, called frame actions, are activated as soon as their keyframe loads.

When you place an action in a keyframe, you don't need to specify an event handler, because the event is implied. Frame actions may look bare, because they lack explicit event handlers, but remember that an event handler actually is present and activeit is just implicit. Frame actions are the only actions that have implicit event handlers.

For basic playback control, the actions discussed in this chapter are most commonly applied to buttons and frame actions, though this relationship is not exclusive. Although these recipes and code examples focus on these objects and their associated events, you can use the same techniques with other objects, events, and event handlers.




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

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