home *** CD-ROM | disk | FTP | other *** search
- class SoundManager
- {
- var MC;
- var played;
- var _vol;
- var start;
- static var myInstance;
- var _enabled = true;
- var muted_vol = 100;
- function SoundManager(_MC)
- {
- this.MC = _MC;
- this.played = new Array();
- this._enabled = true;
- this._vol = 100;
- this.muted_vol = 100;
- }
- static function getInstance()
- {
- if(SoundManager.myInstance == undefined)
- {
- SoundManager.myInstance = new SoundManager();
- }
- return SoundManager.myInstance;
- }
- function setVolume(v)
- {
- this._vol = v;
- play();
- }
- function enable()
- {
- var snd;
- this._enabled = true;
- this._vol = this.muted_vol;
- for(var name in this.played)
- {
- snd = this.played[name];
- snd.setVolume(this._vol);
- }
- }
- function get enabled()
- {
- return this._enabled;
- }
- function isPlaying(soundname, MC)
- {
- var snd = this.played[MC != undefined ? String(MC) : soundname];
- if(snd != undefined)
- {
- return snd.isPlaying;
- }
- return false;
- }
- function mute()
- {
- var snd;
- this._enabled = false;
- this.muted_vol = this._vol;
- this._vol = 0;
- for(var name in this.played)
- {
- snd = this.played[name];
- snd.setVolume(0);
- }
- }
- function remove(soundname)
- {
- if(this.played[soundname] != undefined)
- {
- this.stop(soundname);
- delete this.played[soundname];
- }
- }
- function pause(soundname)
- {
- var snd;
- var p;
- var d;
- snd = this.played[soundname];
- if(snd != undefined)
- {
- p = Math.round(snd.position / 1000);
- d = Math.round(snd.duration / 1000);
- snd.pause = p >= d ? 0 : p;
- snd.isPlaying = false;
- snd.stop();
- }
- else
- {
- for(var name in this.played)
- {
- snd = this.played[name];
- p = Math.round(snd.position / 1000);
- d = Math.round(snd.duration / 1000);
- snd.pause = p >= d ? 0 : p;
- snd.isPlaying = false;
- snd.stop(name);
- }
- }
- }
- function stop(soundname, MC)
- {
- var snd;
- if(soundname != undefined)
- {
- if(MC == undefined)
- {
- snd = this.played[soundname];
- }
- else
- {
- snd = this.played[String(MC)];
- }
- snd.pause = 0;
- snd.isPlaying = false;
- snd.stop(soundname);
- delete snd;
- }
- else
- {
- for(var name in this.played)
- {
- snd = this.played[name];
- snd.stop(name);
- snd.pause = 0;
- snd.isPlaying = false;
- delete snd;
- }
- }
- }
- function play(soundname, loop, MC, oncomplete)
- {
- loop = loop == true;
- var snd;
- if(MC == undefined)
- {
- snd = this.played[soundname] = new Sound();
- }
- else
- {
- snd = this.played[String(MC)] = new Sound();
- }
- snd.isPlaying = true;
- snd.attachSound(soundname);
- snd.start();
- snd.setVolume(this._vol);
- if(loop)
- {
- snd.onSoundComplete = function()
- {
- this.start();
- };
- }
- else
- {
- snd.onSoundComplete = function()
- {
- this.isPlaying = false;
- };
- }
- }
- function onComplete(soundname)
- {
- var snd = this.played[soundname];
- if(snd == undefined)
- {
- return undefined;
- }
- if(snd.onComplete == undefined && snd.loop == false)
- {
- this.remove(soundname);
- }
- else if(snd.loop)
- {
- snd.onComplete();
- snd.start();
- }
- else
- {
- snd.onComplete();
- snd.stop();
- }
- }
- }
-