Stopping Sounds


The default behavior of Event sounds is for them to play through to the end, regardless of the length of the timeline on which they exist. However, you can stop any sound, including Event sounds. Place another instance of the same sound at the keyframe where the sound should stop and assign this instance as a Stop sync option. This Stop setting can be on any layer, and it will stop all instances of the specific sound. Let's give this a try.

Stopping an Event Sound

In this section, we'll show you how to stop an Event sound using two different methods. The first method uses a Stop sound on a keyframe in the Main Timeline (Scene 1). The second method uses a Button instance with a Stop sound on its Down state.

  1. Create a Flash document that has an Event sound placed on the first keyframe and has enough frames on the timeline to display the entire waveform of the sound.

    On the CD-ROM 

    You can use the enhanced_view.fla file from the book's CD-ROM as a practice file. If you use this file, change the sync setting of the sound to Event in the Property inspector.

  2. Create a new layer in the Timeline window, and name this layer stop sound.

  3. On the stop sound layer, pick a frame that's about five seconds into the sound displayed on the original layer.

  4. Create a keyframe on this frame in the stop sound layer.

  5. With this keyframe selected, open the Property inspector.

  6. In the Sound menu, choose the same sound file that was used in the original sound layer.

  7. In the Sync menu of the Property inspector, choose Stop.

    As a Stop sound, this setting will tell the Flash Player to stop any and all instances of the sound that is specified in the Sound menu.

  8. Save your Flash document, and test it (Control ð Test Movie).

    When the Playhead reaches the keyframe with the Stop sound, you should no longer hear the Event sound.

Now, we'll show you how to play and mute an Event sound by clicking buttons. You'll place an Event sound on one Button symbol instance, and then a Stop sound on another Button symbol instance.

  1. In a new Flash document, create a copy of the Play and Stop buttons from the Circle Buttons folder in the Buttons Library (Window ð Common Libraries ð Buttons).

    To do this, drag each of the buttons from the Buttons Library panel to your document's Stage. Close the Buttons Library when you are done. Rename Layer 1 to buttons. Your document's Stage should resemble Figure 15-4.

  2. Import a sound file to use as your Event sound.

    You can use the atmospheres_1.mp3 sound file from the book's CD-ROM.

  3. In the document's Library panel, double-click the Play button to edit the symbol.

  4. In the Timeline window, create a new layer and name it sound.

  5. Insert a keyframe on the Down state of the sound layer.

  6. Select the keyframe made in Step 4, and open the Property inspector.

  7. Select the imported sound's name in the Sound menu, and leave the Sync menu at the default Event setting.

    When you are finished, your document should resemble Figure 15-5.

  8. Double-click the Stop button in the Library panel.

  9. Repeat Steps 3 through 7. This time, however, choose Stop in the Sync menu for the atmospheres_1 sound.

  10. Save your document and test it (Control ð Test Movie).

    In Test Movie mode, click the Play button. You should hear the imported sound begin to play. When you click the Stop button, the sound should stop playing.

image from book Figure 15-4: The Play and Stop buttons on the Stage

image from book
Figure 15-5: This sound will play when the Play button is clicked.

You may have noticed that, if you click the Play button repeatedly, new instances of the sound will begin to play, overlapping with the original playing sound instance. Regardless, the Stop Sync option will stop all of them. If you want to prevent the Play button from enabling this type of overlap, go back to the sound keyframe on the Play button and change its Sync option to Start.

On the CD-ROM 

You can find a completed example of the Play and Stop buttons exercise as stop_sound_100.fla, located in the ch15 folder of the book's CD-ROM.

Stopping a Single Instance of a Stream Sound

You can also stop a single instance of a Stream sound. To do this, simply place an empty keyframe in the sound layer at the point where the sound should stop.

  1. Open the enhanced_view.fla file, located in the ch15 folder of the book's CD-ROM.

  2. Switch the layer view of the atmospheres_1 layer back to 100% in the Layer Properties dialog box.

  3. Select the first frame of the atmospheres_1 layer.

  4. In the Property inspector, switch the Sync option to Stream.

  5. Select frame 60 of the atmospheres_1 layer, and insert a blank keyframe (F7).

    This is the point where the Stream sound will stop playing.

  6. Save your Flash document, and test it (Control ð Test Movie).

    Notice that the sound stops playing at frame 60. You can open your Bandwidth Profiler (View ð Bandwidth Profiler) in the Test Movie mode to see the Playhead move as the movie plays.

The Bandwidth Profiler also reveals something we touched upon earlier: Stream sounds export only the actual portion of the sound that's used in the timeline. In our example, 60 frames' worth of the atmospheres_1 sound was about 12K (at default MP3 compression, 16 kilobits per second, or Kbps).

Stopping All Sounds

You can stop the sounds that are playing in all timelines (including Movie Clips) at any point by doing the following:

  1. If there isn't already an actions layer on your timeline, add a layer, label it actions, and select the frame that occurs at the point where you want all sounds to stop. Make this frame into a keyframe.

  2. With the keyframe selected, open the Actions panel by pressing the F9 key, or by navigating to Window ð Actions.

    The title bar of the Actions panel should read Actions — Frame.

  3. Click the Global Functions booklet in the left pane of the panel, and then click the Timeline Control booklet.

  4. Double-click the stopAllSounds action.

    The ActionScript code,

     stopAllSounds(); 

    appears in the Script pane of the Actions panel, as shown in Figure 15-6.

  5. Save your Flash document, and then test it with Control ð Test Movie.

    When the movie's Playhead reaches the frame with the stopAllSounds() action, every sound that is currently playing stops.

image from book
Figure 15-6: Any sound that's currently playing stops when the movie reaches a keyframe with a stopAllSounds() action.

The stopAllSounds() action stops only sounds that are playing at the time the action is executed. It will not permanently mute the sound for the duration of the movie. You can proceed to re-initialize any sounds any time after the stopAllSounds() action has executed. If you want to stop playback again, you will have to enable another stopAllSounds() action or use a Stop sound.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net