User Guide
208 Chapter 11: Working with Sound
Starting and stopping sounds at keyframes
The most common sound-related task in Flash is starting and stopping sounds at keyframes to
synchronize with animation.
To stop and start a sound at a keyframe:
1.
Add a sound to a document. For more information, see “Adding sounds to a document”
on page 203.
To synchronize this sound with an event in the scene, select a beginning keyframe that
corresponds to the keyframe of the event in the scene. You can select any of the
synchronization options.
2.
Create a keyframe in the sound layer’s Timeline at the frame where you want the sound to end.
A representation of the sound file appears in the Timeline.
3.
Select Window > Properties and click the arrow in the lower right corner to expand the
Property inspector.
4.
In the Property inspector, select the same sound from the Sound pop-up menu.
5.
Select Stop from the Synchronization pop-up menu.
When you play the SWF file, the sound stops playing when it reaches the ending keyframe.
6.
To play back the sound, simply move the playhead.
About the onSoundComplete event
The onSoundComplete event of the ActionScript Sound object lets you trigger an event in a Flash
application based on completing an attached sound file. The Sound object is a built-in object that
lets you control sounds in a Flash application. For more information, see “Sound class” in Flash
ActionScript Language Reference. The
onSoundComplete event of a Sound object is invoked
automatically when the attached sound file finishes playing. If the sound is looped a specified
number of times, the event is triggered when the sound finishes looping.
The Sound object has two properties that you can use with the
onSoundComplete event. The
duration property is a read-only property representing the duration, in milliseconds, of the
sound sample attached to the sound object. The
position property is a read-only property
representing the number of milliseconds the sound has been playing in each loop.
The
onSoundComplete event lets you manipulate sounds in a variety of powerful ways, such as
the following:
• Creating a dynamic playlist or sequencer
• Creating a multimedia presentation that checks for narration completion before advancing to
the next frame or scene
• Building a game that synchronizes sounds to particular events or scenes and transitions
smoothly between different sounds
• Timing an image change to a sound—for example, changing an image when a sound is
half over