This class was especially made for games but can be used for any type of application really. It manages and plays sounds externally loaded or stored in libraries (Flex/Flash). It really provides the basic needs of sound playing in games and still allows you to include your own code for specific functionality if needed. Implementing hundreds of sounds in a game including sound tracks, music tracks, sound effects takes me about one hour for a very complex game. It doesn't get more efficient than that. Main Features:

  1. Load external sound on need basis to save bandwidth. (can be overwriten).
  2. Play, playAt, FadeIn return a SoundChannel for you to use if needed.
  3. PauseAll, stopAll, muteAll, unmuteAll, resumeAll, pause, resume, mute, unmute individual sound as well.
  4. FadeIn, fadeOut.
  5. Autoloop of sounds.
  6. no overlapping of sounds (for specific sounds)
  7. random sound playing (useful for sound effects)
  8. auto setting of volume (can be overwriten anytime)
  9. 2 master volume.
  10. set volume on the fly for specific sound.
  11. Handles automatically 3 type of sound: SOUND a sound effect, usually short duration, can be played multiple times and overlap itself, cannot be paused, resumed, muted.
  12. Handles automatically 3 type of sound: SOUNDTRACK a long duration sound, can be paused, resumed, stopped, muted, cannot overlap itself.
  13. Handles automatically 3 type of sound: LOOPING_SOUNDTRACK same as SOUNDTRACK but looping undefinitely until a call to stop().

Try this little example which includes the 3 type of sound the SoundManager can manage, for the purpose of this example the SOUNDTRACK playing stops the LOOPING_SOUNDTRACK and vice versa:

Some relevant code. Registering sounds and playing them:


SoundManager.getInstance().addClass('effect', Effect1, SoundManager.SOUND, 0.4);
SoundManager.getInstance().addClass('effect', Effect2, SoundManager.SOUND, 0.4);
SoundManager.getInstance().addClass('effect', Effect3, SoundManager.SOUND, 0.4);
SoundManager.getInstance().addClass('track', MasterTrack, SoundManager.SOUNDTRACK, 0.4);
SoundManager.getInstance().addClass('soundtrack', Looping, SoundManager.LOOPING_SOUNDTRACK, 0.4);
//external sound are used this way: SoundManager.getInstance().addSound('effect', 'link to sound', SOUND, 0.4, false, mysoundloadingcontext);

function playLoop(e:MouseEvent):void

function playEffect(e:MouseEvent):void
    //3 sounds are registered with same name so a random one is choosen at play time.

function playTrack(e:MouseEvent):void

It's quite obvious why this class is saving me so much time. You can see that that class uses string names to reference sounds. Those names can easily be setup as static const somewhere (even coming from external data) and played directly that way. A really simple example would be for a simple MouseEvent.CLICK where MouseEvent.CLICK is used as a sound name directly and all that is left to do in the MouseEvent listener is to use SoundManager.getInstance().play(e.type);. note that the SoundManager does not throw error if you try to play a sound that does not exist. There is also two master volume that you can use. One linked to the SOUND type and one linked to SOUNDTRACK and LOOPING_SOUNDTRACK. Those master volume affect the sound volume as it was set. Let's say you have two sound volumes set respectively at 0.4 and 0.8. When the master volume is at 0 both sound volume are at 0, when the master volume is at 1 both sound volume are at 0.4 and 0.8. If you have a mute button in your game you could mute all sounds easily by setting the two master volume to 0 or use directly the pauseAll() method. Check the docs for more in depth covering of that useful class.

That's it for this little article showing 3 useful classes that save me a lot of time on a daily basis and maybe they will save you some time as well!