home *** CD-ROM | disk | FTP | other *** search
- package uk.kerb.utils.sound
- {
- import flash.media.SoundMixer;
- import flash.media.SoundTransform;
-
- public class SoundManager
- {
-
- private static var allowInstantiation:Boolean = false;
-
- private static var instance:SoundManager = null;
-
-
- private var sounds:Array;
-
- private var preMuteVolume:Number = 1;
-
- private var muteState:Boolean = false;
-
- private var masterVolume:Number = 1;
-
- public function SoundManager()
- {
- sounds = new Array();
- super();
- if(!allowInstantiation || instance != null)
- {
- throw new Error("SoundManager is a singleton - use SoundManager.getInstance()");
- }
- }
-
- public static function getInstance() : SoundManager
- {
- if(instance == null)
- {
- allowInstantiation = true;
- instance = new SoundManager();
- allowInstantiation = false;
- }
- return instance;
- }
-
- public function stopAllSounds() : void
- {
- SoundMixer.stopAll();
- }
-
- public function getSoundFromID(param1:String) : ExtendedSound
- {
- return sounds[param1];
- }
-
- public function get muted() : Boolean
- {
- return muteState;
- }
-
- public function registerSound(param1:ExtendedSound, param2:String) : void
- {
- if(sounds[param2] != null)
- {
- throw new Error("ID conflict: A sound with the id [" + param2 + "] already exists in SoundManager\'s sound list.");
- }
- sounds[param2] = param1;
- }
-
- public function unmute() : void
- {
- muteState = false;
- setMasterVolume(preMuteVolume);
- }
-
- public function mute() : void
- {
- muteState = true;
- preMuteVolume = masterVolume;
- setMasterVolume(0);
- }
-
- public function setMasterVolume(param1:Number) : void
- {
- masterVolume = Math.max(0,Math.min(1,param1));
- var _loc2_:SoundTransform = SoundMixer.soundTransform;
- _loc2_.volume = masterVolume;
- SoundMixer.soundTransform = _loc2_;
- }
- }
- }
-