O'Reilly logo

Flash 8 Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required