home *** CD-ROM | disk | FTP | other *** search
- class manage.SoundManage
- {
- var soundList;
- var musicList;
- var isMusicPlay;
- var isSoundPlay;
- var soundMc;
- var soundTime;
- var soundTimeMax;
- var soundObject;
- var onEnterFrame;
- function SoundManage()
- {
- _root.createEmptyMovieClip("mysound_mc",_root.getNextHighestDepth());
- _root.createEmptyMovieClip("mymusic_mc",_root.getNextHighestDepth());
- this.soundList = new Object();
- this.musicList = new Object();
- this.addMusic("main_s");
- if(this.isMusicPlay == undefined)
- {
- this.isMusicPlay = true;
- this.playMusic("main_s",999999);
- }
- if(this.isSoundPlay == undefined)
- {
- this.isSoundPlay = true;
- }
- }
- function addMusicOverTime(str, timeNo, frameNo)
- {
- var _loc2_ = this.musicList[str];
- if(_loc2_)
- {
- _loc2_.sound.soundManage = this;
- _loc2_.sound.soundMc = _loc2_.mc;
- _loc2_.sound.soundMc.soundTimeMax = frameNo;
- _loc2_.sound.onSoundComplete = function()
- {
- this.soundMc.soundObject = this;
- this.soundMc.soundTime = 0;
- this.soundMc.onEnterFrame = function()
- {
- this.soundTime = this.soundTime + 1;
- if(this.soundTime >= this.soundTimeMax)
- {
- this.soundObject.start(0,1);
- delete this.onEnterFrame;
- }
- };
- };
- }
- }
- function addSound()
- {
- this.addSound2(this.soundList,arguments);
- }
- function addMusic()
- {
- this.addSound2(this.musicList,arguments);
- }
- function addSound2(list, args)
- {
- var _loc10_ = args.length;
- var _loc6_ = -1;
- while((_loc6_ = _loc6_ + 1) < _loc10_)
- {
- var _loc4_ = args[_loc6_];
- if(typeof _loc4_ == "string")
- {
- var _loc0_ = null;
- var _loc3_ = list[_loc4_] = {};
- var _loc5_ = undefined;
- if(list == this.musicList)
- {
- _loc5_ = _root.mymusic_mc;
- }
- else
- {
- _loc5_ = _root.mysound_mc;
- }
- _loc3_.mc = _loc5_.createEmptyMovieClip(_loc4_ + "_sound",_loc5_.getNextHighestDepth());
- _loc3_.sound = new Sound(_loc3_.mc);
- _loc3_.name = _loc4_;
- _loc3_.sound.attachSound(_loc3_.name);
- var _loc7_ = args[_loc6_ + 1];
- if(typeof _loc7_ == "number")
- {
- _loc3_.vol = this.adjustVolume(_loc7_);
- _loc3_.sound.setVolume(_loc3_.vol);
- _loc6_ = _loc6_ + 1;
- }
- else
- {
- _loc3_.vol = 100;
- }
- trace("加入音效:" + _loc4_ + "音量为:" + _loc3_.sound.getVolume());
- }
- }
- }
- function stopSound()
- {
- this.stopSound2(this.soundList,"stop",arguments);
- }
- function stopMusic()
- {
- this.stopSound2(this.musicList,"volume",arguments);
- }
- function stopMusic2()
- {
- this.stopSound2(this.musicList,"stop",arguments);
- }
- function stopSound2(list, action, args)
- {
- var _loc0_ = null;
- if((_loc0_ = action) !== "stop")
- {
- if(args.length > 0)
- {
- for(var _loc3_ in args)
- {
- list[args[_loc3_]].sound.setVolume(0);
- }
- }
- else
- {
- for(_loc3_ in list)
- {
- list[_loc3_].sound.setVolume(0);
- }
- }
- }
- else if(args.length > 0)
- {
- for(_loc3_ in args)
- {
- list[args[_loc3_]].sound.stop();
- }
- }
- else
- {
- for(_loc3_ in list)
- {
- list[_loc3_].sound.stop();
- }
- }
- }
- function returnSound()
- {
- this.isSoundPlay = true;
- for(var _loc2_ in this.soundList)
- {
- this.soundList[_loc2_].sound.setVolume(this.soundList[_loc2_].vol);
- }
- }
- function returnMusic()
- {
- this.isMusicPlay = true;
- for(var _loc2_ in this.musicList)
- {
- this.musicList[_loc2_].sound.setVolume(this.musicList[_loc2_].vol);
- }
- }
- function adjustVolume(vol)
- {
- if(isNaN(vol))
- {
- return 100;
- }
- if(vol > 100)
- {
- return 100;
- }
- if(vol < 0)
- {
- return 0;
- }
- return vol;
- }
- function setSoundVol()
- {
- this.setSoundVol2(this.soundList,arguments);
- }
- function setMusicVol()
- {
- this.setSoundVol2(this.musicList,arguments);
- }
- function setSoundVol2(list, args)
- {
- var _loc9_ = args.length;
- if(_loc9_ > 0)
- {
- if(_loc9_ == 1)
- {
- var _loc7_ = this.adjustVolume(args[0]);
- for(var _loc4_ in list)
- {
- list[_loc4_].vol = _loc7_;
- list[_loc4_].sound.setVolume(_loc7_);
- }
- }
- else
- {
- _loc4_ = -1;
- while((_loc4_ = _loc4_ + 1) < _loc9_)
- {
- var _loc3_ = args[_loc4_];
- if(typeof _loc3_ == "string")
- {
- var _loc2_ = list[_loc3_];
- var _loc6_ = args[_loc4_ + 1];
- if(typeof _loc6_ == "number")
- {
- _loc2_.vol = this.adjustVolume(_loc6_);
- _loc4_ = _loc4_ + 1;
- }
- else
- {
- _loc2_.vol = 100;
- }
- _loc2_.sound.setVolume(_loc2_.vol);
- }
- trace("设置音效:" + _loc3_ + "音量为:" + _loc2_.sound.getVolume());
- }
- }
- }
- }
- function playSound()
- {
- if(this.isSoundPlay == true)
- {
- this.playSound2(this.soundList,arguments);
- }
- }
- function playMusic()
- {
- if(this.isMusicPlay == true)
- {
- this.playSound2(this.musicList,arguments);
- }
- }
- function playSound2(list, args)
- {
- var _loc5_ = args[0];
- var _loc2_ = args[1];
- if(isNaN(_loc2_))
- {
- _loc2_ = 1;
- }
- var _loc3_ = args[2];
- var _loc4_ = list[_loc5_];
- _loc4_.sound.start(0,_loc2_);
- if(!isNaN(_loc3_))
- {
- _loc4_.setVolume(this.adjustVolume(_loc3_));
- }
- }
- function isTrueStopSound()
- {
- this.stopSound2(this.soundList,"stop",arguments);
- }
- function isTrueStopMusic()
- {
- this.stopSound2(this.musicList,"stop",arguments);
- }
- function clearSoundAndMusic()
- {
- for(var _loc3_ in _root.mymusic_mc)
- {
- removeMovieClip(_root.mymusic_mc[_loc3_]);
- }
- for(_loc3_ in _root.mysound_mc)
- {
- removeMovieClip(_root.mysound_mc[_loc3_]);
- }
- removeMovieClip(_root.mysound_mc);
- removeMovieClip(_root.mymusic_mc);
- this.soundList = null;
- this.musicList = null;
- delete this.soundList;
- delete this.musicList;
- }
- }
-