Tài liệu Reacting to Dynamically Loaded MP3s - Pdf 87


< Day Day Up > < Day Day Up >

Reacting to Dynamically Loaded MP3s
Want to trigger a set of actions to execute when a sound has finished playing? Want to
know a sound's duration (play length) or current position (playback position)? Flash
provides you with precisely this type of dynamic control when using loaded MP3s (or
even internally attached sounds).
NOTE
Lesson 17
, "Scripting for Sound," discussed many of the ways that you can control
sounds dynamically.

It's often useful to know when a sound will finish playing. Consider a presentation in
which the next screen of info should be displayed only after the voiceover has finished
explaining the current screen. Or a music jukebox that automatically loads the next song
when the current one has finished playing. You can easily achieve this type of
functionality 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 in
the Sound object finishes playing. The Sound class also provides two other events,

In the following exercise, we'll use the onSoundComplete event to trigger a function.

< Day Day Up >

We'll also employ the duration and position properties of the Sound object to create a
playback progress bar.
1. Open virtualaquarium7.fla.
We'll 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.

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 instance's timeline to the
appropriate frame. Together, these actions emulate the functionality of a progress
bar.
The if/else statement makes the progress bar invisible when progressAmount has a
value of 100, as when the last image/sound has been shown/played. The progress
bar will be visible anytime this value is less than 100 (whenever a sound is still
playing).
5. Choose Control > Test Movie.
If you let the project play by itself, after the first loaded sound finishes playing, the
project automatically advances to the next image/sound and then repeats this
process. Notice that the progress bar tracks the playback of the sound as well.

After the third image/sound has loaded and finished playing, the presentation stops
and the progress bar disappears because there is no more content to load, as
defined in the slides array. Only by pressing the left-arrow button can you bring
the presentation to life again.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status