10.7. Creating Seek Buttons
Problem
You want the timeline to fast-forward or rewind visually as long as the user holds down a button.
Solution
Use the gotoAndStop( ) method in conjunction with the _currentframe
property to skip back or forward in the timeline. Add the gotoAndStop( ) method within an onEnterFrame( ) event handler method, so that it gets called repeatedly at the frame rate of the movie. Use button event handler methods to define and remove the onEnterFrame( ) method based on the state of the button.
Discussion
In Recipe 10.6, you learned how to play a movie clip’s timeline in reverse. Using very similar principals, you can add functionality to your Flash movie that causes a timeline to visually rewind or fast forward. There are several elements involved. First, you need to create buttons to trigger the rewind and fast-forward functionality. Then, you need to apply onPress( ) and onRelease( ) event handler methods to the buttons. Within the onPress( ) event handler methods, define an onEnterFrame( ) event handler method for the movie clip you want to affect. The onRelease( ) event handler method should remove the onEnterFrame( ) definition. That may sound like a lot of information, so here’s an example.
Imagine that you have a button on the main timeline with an instance name btRewind
. Also on the main timeline is a movie clip with an instance name of mAnimation
. When the user clicks on the btRewind
button, you want the timeline of mAnimation
to play in reverse rapidly. ...
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.