home *** CD-ROM | disk | FTP | other *** search
- class illusoft.utils.Sounds
- {
- var dmc;
- var sounds;
- var soundsmc;
- var start;
- var currentMusicName;
- var onEnterFrame;
- var isPlaying;
- var soundEnabled = true;
- function Sounds(mc)
- {
- this.dmc = mc.createEmptyMovieClip("sounds",mc.getNextHighestDepth());
- this.Init();
- }
- function CreateSound(soundName)
- {
- var _loc2_ = this.dmc.createEmptyMovieClip(soundName,this.dmc.getNextHighestDepth());
- _loc2_.isPlaying = false;
- var _loc3_ = new Sound(_loc2_);
- _loc3_.attachSound("snd_" + soundName);
- this.sounds[soundName] = _loc3_;
- this.soundsmc[soundName] = _loc2_;
- }
- function Init()
- {
- this.sounds = new Array();
- this.soundsmc = new Array();
- this.CreateSound("child");
- this.CreateSound("jetstream");
- this.CreateSound("bling");
- this.CreateSound("surprise");
- this.CreateSound("jippie");
- this.CreateSound("jippie2");
- this.CreateSound("door");
- this.CreateSound("explode");
- this.CreateSound("boing");
- this.CreateSound("loop0");
- this.CreateSound("loop1");
- this.CreateSound("loop2");
- this.CreateSound("loop3");
- this.CreateSound("loop4");
- this.CreateSound("map");
- this.CreateSound("victory");
- this.CreateSound("game_over");
- this.CreateSound("water");
- this.CreateSound("hit");
- this.CreateSound("waterpao");
- this.CreateSound("boing2");
- this.CreateSound("boing3");
- this.CreateSound("stoneboing");
- this.CreateSound("stonemove");
- this.CreateSound("win");
- this.CreateSound("niao");
- this.CreateSound("snow");
- this.CreateSound("over");
- this.CreateSound("timeout");
- this.CreateSound("in");
- this.CreateSound("fei");
- this.CreateSound("bee");
- this.CreateSound("bs");
- this.CreateSound("x");
- this.CreateSound("sw");
- this.CreateSound("fc");
- this.CreateSound("ju");
- }
- function PlaySound(soundName, Volume)
- {
- if(Volume == null)
- {
- Volume = 100;
- }
- if(this.soundEnabled)
- {
- var _loc3_ = this.soundsmc[soundName];
- _loc3_.onEnterFrame = null;
- var _loc2_ = this.sounds[soundName];
- _loc2_.stop();
- _loc2_.setVolume(Volume);
- _loc2_.start(0,1);
- }
- }
- function StopSound(soundName)
- {
- var _loc3_ = this.sounds[soundName];
- var _loc2_ = this.soundsmc[soundName];
- _loc3_.stop();
- _loc2_.isPlaying = false;
- }
- function LoopSound(soundName, Volume)
- {
- if(Volume == null)
- {
- Volume = 100;
- }
- if(this.soundEnabled)
- {
- var _loc3_ = this.sounds[soundName];
- var _loc2_ = this.soundsmc[soundName];
- if(!_loc2_.isPlaying)
- {
- _loc2_.isPlaying = true;
- _loc3_.start(0,1);
- _loc3_.onSoundComplete = function()
- {
- this.start(0,1);
- };
- }
- else
- {
- this.FadeVolume(soundName,true,false,3,Volume);
- }
- }
- }
- function StartMusic(musicName, Volume)
- {
- if(Volume == null)
- {
- Volume = 70;
- }
- this.FadeMusic();
- if(this.soundEnabled)
- {
- var _loc3_ = this.soundsmc[musicName];
- _loc3_.onEnterFrame = null;
- var _loc2_ = this.sounds[musicName];
- _loc2_.stop();
- _loc2_.setVolume(Volume);
- _loc2_.start(0,999);
- }
- this.currentMusicName = musicName;
- }
- function FadeMusic()
- {
- if(this.currentMusicName != null)
- {
- this.sounds[this.currentMusicName].stop();
- this.currentMusicName = null;
- }
- }
- function FadeAllMusic()
- {
- if(this.currentMusicName != null)
- {
- this.FadeVolume(this.currentMusicName,false,false,1);
- this.currentMusicName = null;
- }
- }
- function ToggleSound(mc)
- {
- this.soundEnabled = !this.soundEnabled;
- if(this.soundEnabled)
- {
- mc.gotoAndStop("on");
- if(this.currentMusicName != null)
- {
- this.StartMusic(this.currentMusicName);
- }
- }
- else
- {
- mc.gotoAndStop("off");
- for(var _loc2_ in this.sounds)
- {
- this.FadeVolume(_loc2_,false,false,null);
- }
- }
- }
- function FadeVolume(soundName, louder, fromStart, speed, Volume)
- {
- if(speed == null)
- {
- speed = 3;
- }
- if(Volume == null)
- {
- Volume = 100;
- }
- var snd = this.sounds[soundName];
- var _loc2_ = this.soundsmc[soundName];
- if(fromStart)
- {
- if(louder)
- {
- snd.setVolume(1);
- snd.start(0,1);
- _loc2_.isPlaying = true;
- }
- else
- {
- snd.setVolume(Volume - 1);
- }
- }
- if(louder)
- {
- _loc2_.onEnterFrame = function()
- {
- snd.setVolume(snd.getVolume() + speed);
- if(snd.getVolume() >= Volume - 1)
- {
- snd.setVolume(Volume);
- delete this.onEnterFrame;
- }
- };
- }
- else
- {
- _loc2_.onEnterFrame = function()
- {
- snd.setVolume(snd.getVolume() - speed);
- if(snd.getVolume() <= 0)
- {
- snd.stop();
- snd.setVolume(Volume);
- this.isPlaying = false;
- delete this.onEnterFrame;
- }
- };
- }
- }
- }
-