Reacting to Dynamically Loaded MP3s
Số trang: 5
Loại file: pdf
Dung lượng: 19.28 KB
Lượt xem: 10
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Phản ứng với động các Loaded MP3 Bạn muốn kích hoạt một bộ các hành động để thực hiện khi một âm thanh đã hoàn tất chơi? Bạn muốn biết thời gian của âm thanh (chơi dài) hoặc hiện tại vị trí (phát lại vị trí)?
Nội dung trích xuất từ tài liệu:
Reacting to Dynamically Loaded MP3s < Day Day Up > < Day Day Up >Reacting to Dynamically Loaded MP3sWant to trigger a set of actions to execute when a sound has finished playing? Want toknow a sounds duration (play length) or current position (playback position)? Flashprovides you with precisely this type of dynamic control when using loaded MP3s (oreven internally attached sounds).NOTELesson 17, Scripting for Sound, discussed many of the ways that you can controlsounds dynamically.Its often useful to know when a sound will finish playing. Consider a presentation inwhich the next screen of info should be displayed only after the voiceover has finishedexplaining the current screen. Or a music jukebox that automatically loads the next songwhen the current one has finished playing. You can easily achieve this type offunctionality by using the onSoundComplete event handler:mySoundObject.onSoundComplete = function(){ //actions go here...}Using this syntax, you would define a series of actions to be triggered when the sound inthe Sound object finishes playing. The Sound class also provides two other events,onLoad and onID3, which well discuss in the next exercise.NOTEA Sound object must exist in your movie before you can define an onSoundCompleteevent handler to it. If you delete or re-create the Sound object, you must redefine theonSoundComplete event. In other words, you cant attach an event to an object thatdoesnt exist, and after an object has been deleted or re-created, the attached event ceasesto exist as well. < Day Day Up >Every Sound object has a duration property, representing the sounds length (in milliseconds). Accessing this propertys value is accomplished in the following manner:var soundDuration:Number = mySoundObject.duration;This script sets the value of soundDuration to the duration of the sound currently in thereferenced Sound object. If the sound is 5.5 seconds long, the value of soundDuration isset to 5500 (1,000 x 5.5). This property exists for loaded sounds as well as soundsattached to the Sound object by using attachSound().You can determine how far a sound has progressed in its playback by using the followingsyntax:var soundPosition:Number = mySoundObject.position;If the sound in the referenced Sound object has been playing for three seconds,soundPosition is set to a value of 3000 (1,000 x 3).In the following exercise, well use the onSoundComplete event to trigger a function. < Day Day Up >Well also employ the duration and position properties of the Sound object to create aplayback progress bar. 1. Open virtualaquarium7.fla. Well add some script to Frame 1 of this file from the preceding exercise, as well as add a simple script to the progress_mc movie clip instance (which is below the panel graphic). 2. With the Actions panel open, select Frame 1 of the Actions layer and add the following lines of script at the end of (but within) the if statement of the changeSlide() function definition: 3. 4. slideSound.onSoundComplete = function(){ 5. 6. changeSlide(currentSlide + 1); 7. 8. } 9. This script defines what should occur when the sound loaded into the slideSound Sound object has finished playing. A call is made to the changeSlide() function. < Day Day Up > This call acts as an automatic advancing mechanism for the slideshow: As soon as a sound has finished playing, the next image and sound are loaded as a result of the function call to the changeSlide() function. In the preceding exercise, we discussed how our slideSound Sound object is re- created/reinitialized each time before a new sound is loaded into it. Every time this occurs, the event handler is removed from the Sound object instance as well. By placing this script just a few lines after the Sound objects reinitialization, we reattach this onSoundComplete event handler to the Sound object. Lets look at the structure of the playback progress bar before we script it.3. Double-click the progress_mc movie clip instance to edit it in place. This movie clip is made up of three layers. Were most interested in the bottom layer, named bar, which contains a 100-frame tween. If you drag the playhead, youll see that this tween is set up to emulate a progress bar with a range of 0 to 100 percent. In a moment, well add a script to move this timeline to the appropriate frame based on the percentage of the sound file that has played. In other words, if 47 percent of the sound file has played, this clip will be at Frame 47, showing the appropriate progress.4. 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:5.6. progress_mc.onEnterFrame = function(){7.8. var progressAmount = Math.round(((slideSound.position / slideSound.duration) * 100));9.10. this.gotoAndStop(progressAmount);11.12. if (progressAmount == 100){13.14. this._visible = false;15.16. }else{17.18. this._visible = true;19.20. }21.22. } < Day Day Up >23. This script attaches an event handler to the progress_mc instance. For each onEnterFrame event, the value of progressAmount is updated to a percentage value between 0 and 100. This percentage value is determined by evaluating the current position and duration values of the slideSound Sound object and then rounding the result. This value is next used to move the instances timeline to the appropriate frame. Together, these actions emu ...
Nội dung trích xuất từ tài liệu:
Reacting to Dynamically Loaded MP3s < Day Day Up > < Day Day Up >Reacting to Dynamically Loaded MP3sWant to trigger a set of actions to execute when a sound has finished playing? Want toknow a sounds duration (play length) or current position (playback position)? Flashprovides you with precisely this type of dynamic control when using loaded MP3s (oreven internally attached sounds).NOTELesson 17, Scripting for Sound, discussed many of the ways that you can controlsounds dynamically.Its often useful to know when a sound will finish playing. Consider a presentation inwhich the next screen of info should be displayed only after the voiceover has finishedexplaining the current screen. Or a music jukebox that automatically loads the next songwhen the current one has finished playing. You can easily achieve this type offunctionality by using the onSoundComplete event handler:mySoundObject.onSoundComplete = function(){ //actions go here...}Using this syntax, you would define a series of actions to be triggered when the sound inthe Sound object finishes playing. The Sound class also provides two other events,onLoad and onID3, which well discuss in the next exercise.NOTEA Sound object must exist in your movie before you can define an onSoundCompleteevent handler to it. If you delete or re-create the Sound object, you must redefine theonSoundComplete event. In other words, you cant attach an event to an object thatdoesnt exist, and after an object has been deleted or re-created, the attached event ceasesto exist as well. < Day Day Up >Every Sound object has a duration property, representing the sounds length (in milliseconds). Accessing this propertys value is accomplished in the following manner:var soundDuration:Number = mySoundObject.duration;This script sets the value of soundDuration to the duration of the sound currently in thereferenced Sound object. If the sound is 5.5 seconds long, the value of soundDuration isset to 5500 (1,000 x 5.5). This property exists for loaded sounds as well as soundsattached to the Sound object by using attachSound().You can determine how far a sound has progressed in its playback by using the followingsyntax:var soundPosition:Number = mySoundObject.position;If the sound in the referenced Sound object has been playing for three seconds,soundPosition is set to a value of 3000 (1,000 x 3).In the following exercise, well use the onSoundComplete event to trigger a function. < Day Day Up >Well also employ the duration and position properties of the Sound object to create aplayback progress bar. 1. Open virtualaquarium7.fla. Well add some script to Frame 1 of this file from the preceding exercise, as well as add a simple script to the progress_mc movie clip instance (which is below the panel graphic). 2. With the Actions panel open, select Frame 1 of the Actions layer and add the following lines of script at the end of (but within) the if statement of the changeSlide() function definition: 3. 4. slideSound.onSoundComplete = function(){ 5. 6. changeSlide(currentSlide + 1); 7. 8. } 9. This script defines what should occur when the sound loaded into the slideSound Sound object has finished playing. A call is made to the changeSlide() function. < Day Day Up > This call acts as an automatic advancing mechanism for the slideshow: As soon as a sound has finished playing, the next image and sound are loaded as a result of the function call to the changeSlide() function. In the preceding exercise, we discussed how our slideSound Sound object is re- created/reinitialized each time before a new sound is loaded into it. Every time this occurs, the event handler is removed from the Sound object instance as well. By placing this script just a few lines after the Sound objects reinitialization, we reattach this onSoundComplete event handler to the Sound object. Lets look at the structure of the playback progress bar before we script it.3. Double-click the progress_mc movie clip instance to edit it in place. This movie clip is made up of three layers. Were most interested in the bottom layer, named bar, which contains a 100-frame tween. If you drag the playhead, youll see that this tween is set up to emulate a progress bar with a range of 0 to 100 percent. In a moment, well add a script to move this timeline to the appropriate frame based on the percentage of the sound file that has played. In other words, if 47 percent of the sound file has played, this clip will be at Frame 47, showing the appropriate progress.4. 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:5.6. progress_mc.onEnterFrame = function(){7.8. var progressAmount = Math.round(((slideSound.position / slideSound.duration) * 100));9.10. this.gotoAndStop(progressAmount);11.12. if (progressAmount == 100){13.14. this._visible = false;15.16. }else{17.18. this._visible = true;19.20. }21.22. } < Day Day Up >23. This script attaches an event handler to the progress_mc instance. For each onEnterFrame event, the value of progressAmount is updated to a percentage value between 0 and 100. This percentage value is determined by evaluating the current position and duration values of the slideSound Sound object and then rounding the result. This value is next used to move the instances timeline to the appropriate frame. Together, these actions emu ...
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 245 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 235 1 0 -
47 trang 233 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 228 0 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 227 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 226 0 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 196 0 0 -
80 trang 194 0 0
-
122 trang 189 0 0
-
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 182 0 0