Previous Page
Next Page

Recipe 15.12. Stopping All Sounds

Problem

You want to stop all currently playing sounds.

Solution

Use the stopAll( ) method of the SoundMixer object.

Discussion

As mentioned earlier, whenever you start playing a sound, it creates a SoundChannel object. You can play multiple sounds in a .swf, and each one will be assigned to a separate sound channel. Some aspects of a sound are controlled via the Sound object itself, some from the sound channel. In the end, all of the currently playing channels are mixed together to create the final sound coming from the speakers. The object responsible for this is the SoundMixer object. Its properties and methods apply to all the sounds in the movie as they are mixed together.

One of these methods is the stopAll( ) method. As expected, this stops every currently playing sound in the .swf.

Although sound can greatly enhance the experience of a web site, game, etc., you should always give the user the option to turn off the sound. The stopAll( ) method is the simplest way to do this. It is a static method of the SoundMixer class, so you can call it directly from there. Usually this would be done in an event handler attached to a button or sprite, like so:

public function stopSounds(event:Event):void {
    SoundMixer.stopAll(  );
}

See Also

Recipe 15.2


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)