TAILIEUCHUNG - Học Actionscript 3.0 - p 13

Playhead Movement Figure 5-1. demonstrates simple navigation Placing a stop() action in any frame script is a means of halting playback of that timeline without user interaction—perhaps at the end of an animation or to support a menu or similar need to display a single frame. Only the timeline in which the stop() action is used will stop, so if the main timeline is stopped, movie clips will continue to animate. Let’s take a more interactive approach and look at invoking the stop() action via user input, such as clicking a button. Line 1 of the following script is an event. | Playhead Movement Figure 5-1. demonstrates simple navigation Placing a stop action in any frame script is a means of halting playback of that timeline without user interaction perhaps at the end of an animation or to support a menu or similar need to display a single frame. Only the timeline in which the stop action is used will stop so if the main timeline is stopped movie clips will continue to animate. Let s take a more interactive approach and look at invoking the stop action via user input such as clicking a button. Line 1 of the following script is an event listener added to a button named stopBtn. It uses a mouse click to call onStopClick the function defined in Lines 3 through 5. 1 onStopClick 2 false 0 true 3 function onStopClick evt MouseEvent void 4 stop 5 All playback of the main timeline will cease when the user clicks the button. Adding the following lines to the script will allow you to restart playback. The new code is similar to the previous example but invokes the play method from the playBtn instead. Using this pair of buttons you can start and stop playback at any time without relocating the playback head in the process. NOTE If you don t know about event listeners or typed arguments consult Chapter 3 for more information. Be sure to pay particular attention to the sidebar Garbage Collection on weak references. 6 onPlayClick 7 false 0 true 8 function onPlayClick evt MouseEvent void 9 play 10 Chapter 5 Timeline Control 19 Download from Wow eBook Playhead Movement NOTE Organizing your code is a very personal thing subject to preference. Many coders group listener objects like buttons together and place the corresponding functions soon after. This allows you to look at all the buttons at once without scrolling through all the functions. Others like to group the listener object and function together so the functionality of the .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.