« Home « Kết quả tìm kiếm

Controlling the Playback Speed and Direction of a Timeline


Tóm tắt Xem thử

- methods of the MovieClip class.
- myButton_btn.onRelease = function(){.
- myMovieClip_mc.nextFrame();.
- myMovieClip_mc.prevFrame();.
- By assigning these event handlers to buttons, you can create navigation controls that automatically advance or rewind a timeline one frame at a time with each click of the button..
- For example, if the main movie is being played, the following script places the numerical value of the playhead's current frame position into a variable named whereAreWe:.
- In the following example, the playhead on the main timeline advances 10 frames from its current position:.
- In the same way, you can use the following script to make the timeline move backward 10 frames:.
- As the following exercise demonstrates, by using the onEnterFrame event to execute a line of script such as the one above, you can create fast forward and rewind buttons to control a timeline's playback..
- most of the work for this exercise focuses on the Messages section of the application.
- In this area are four buttons named play_btn, stop_btn, ff_btn, and rew_btn, and a graphically empty movie clip named messages_mc.
- The four buttons eventually will be scripted to control the messages_mc timeline.
- Double-click the messages_mc movie clip instance to edit it in place..
- Frame 1 of the Actions layer contains a stop() action to prevent the timeline from moving forward until we instruct it to do so.
- Return to the main timeline.
- With the Actions panel open, select Frame 1 of the Actions layer and add the following script at the end of the current script:.
- The first line of the script creates a Sound object named fastSound.
- This Sound object eventually will be scripted to play a fast-forwarding sound when the messages_mc timeline is fast-forwarded or rewound..
- The remaining lines of the script are the beginnings of the handleMessages() function.
- This function accepts a single parameter named action, which contains a string value of "play stop ff", or "rew".
- function whether it should play, stop, fast-forward, or rewind the messages_mc timeline.
- As we'll describe shortly, this function will be called and passed various parameter values when you interact with one of the playback control buttons..
- Insert the following conditional statement within the handleMessage() function definition:.
- delete messages_mc.onEnterFrame;.
- messages_mc.play();.
- messages_mc.stop();.
- "ff"){.
- messages_mc.onEnterFrame = function(){.
- Before we discuss how the first part of the conditional statement works, you should be aware of two events that occur later in the statement when the function is passed a value of "ff".
- forwarding sound is attached to the fastSound Sound object and played, and the functionality for carrying out either the fast-forwarding or rewinding of the messages_mc timeline is accomplished via an onEnterFrame that gets attached to the messages_mc instance.
- If the handleMessages() function is passed a value of "play", the first part of this conditional statement is executed.
- If the function is passed a value of "stop", the second part of the conditional.
- This part of the statement does almost the same thing as the first, except that the stop() command stops the messages_mc timeline from.
- If the handleMessages() function is not passed either a value of "play".
- or "stop", the last part of the conditional statement (else) is executed.
- If this part of the statement is executed, the function has been passed a value of "ff".
- This part of the conditional statement has a nested if/else statement.
- Whenever the messages_mc timeline is either fast-forwarded or rewound as a result of this function's being passed a value of "ff".
- The first two lines of script within the else part of the statement handle this common functionality in either case.
- Following that, the value of action is further evaluated.
- If action has a value of "ff", an onEnterFrame event handler is attached to the messages_mc instance.
- This event handler advances the messages_mc timeline to its current frame, plus 3.
- If action has a value of "rew", the actions in the nested else statement are executed.
- This is much like the script we just discussed, except that it moves the messages_mc timeline backward 10 frames with every onEnterFrame event, moving the timeline in reverse very rapidly..
- To reiterate a point made earlier, fast-forwarding or rewinding continue until the onEnterFrame event is deleted from the messages_mc instance.
- the handleMessages() function is passed a value of "play".
- The handleMessages() function is complete.
- Add the following script at the end of the current script:.
- play_btn.onRelease = function(){.
- stop_btn.onRelease = function(){.
- ff_btn.onPress = function(){.
- ff_btn.onRelease = function(){.
- rew_btn.onPress = function(){.
- rew_btn.onRelease = function(){.
- When the movie appears, use the various buttons to control the playback of the messages_mc movie clip instance

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt