10.4. Skipping the Playhead to a Different Frame of the Timeline
Problem
You want to skip the playhead ahead or back within a timeline.
Solution
Use the MovieClip.gotoAndPlay( ) or MovieClip.gotoAndStop( ) method. Optionally, if you want to specify a scene to which you want to have the playhead move, you may use the gotoAndPlay( ) or gotoAndStop( ) global function.
If you want to simply move the playhead to the next frame or the previous frame, use the MovieClip.nextFrame( ) or MovieClip.prevFrame( ) method.
Discussion
Flash has several ways by which you can instruct the playhead to move to a specific frame in a timeline. Some of the ways tell the playhead to go to a frame and then keep playing from there. Others tell the playhead to go to a frame and then stop. That is logical enough. But what may not be obvious is the reasoning for two sets of each. You can use either the methods of the MovieClip class or the global functions of the same name. Typically, the methods of the MovieClip class are preferable, because they allow more flexibility in most ways than the global function counterparts. The global functions remain in Flash, because the MovieClip class methods were not introduced until Flash 5. That means that for Flash to continue to support Flash 4 content, it must support the global functions.
Both the gotoAndPlay( ) and gotoAndStop( ) methods of the MovieClip class skip the playhead to a specific frame of the timeline. As their names suggest, gotoAndPlay( ) skips the playhead ...
Get Flash 8 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.