home *** CD-ROM | disk | FTP | other *** search
- package Gamefile
- {
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.utils.getDefinitionByName;
-
- public class SoundsManager
- {
-
- public static var enabled:Boolean;
-
- private static const SOUNDSLINK:Array = ["_GameMouseDown_","_GameMouseOver_","_MenuMouseDown_","_MenuMouseOver_","_WalkLoop_","_PonderosityAnimal_","_ModerateAnimal_","_SmallAnimal_","_Elephant_S_","_Squirrel_S_","_Flamingo_S_","_Panda_S_","_Chick_S_","_Cat_S_","_Hippo_S_","_Snake_S_","_SnakeMove_S_","_Whale_S_"];
-
- private static var currentMusic:String;
-
- private static const VALUEMUSIC:Number = 1;
-
- private static var soundsArr:Array;
-
- private static const VALUESOUND:Number = 1;
-
-
- public function SoundsManager()
- {
- super();
- init();
- setEnabled(true);
- }
-
- public static function stopMusic() : void
- {
- var _loc1_:int = 0;
- var _loc2_:Object = null;
- if(currentMusic != null)
- {
- _loc1_ = 0;
- while(_loc1_ < soundsArr.length)
- {
- _loc2_ = soundsArr[_loc1_];
- if(_loc2_.label == currentMusic)
- {
- if(_loc2_.channel != null)
- {
- _loc2_.channel.stop();
- _loc2_.channel = null;
- }
- }
- _loc1_++;
- }
- }
- }
-
- public static function StopSound(param1:String) : void
- {
- var _loc2_:int = 0;
- var _loc3_:Object = null;
- _loc2_ = 0;
- while(_loc2_ < soundsArr.length)
- {
- _loc3_ = soundsArr[_loc2_];
- if(_loc3_.label == param1)
- {
- if(_loc3_.channel != null)
- {
- _loc3_.channel.stop();
- _loc3_.channel = null;
- }
- }
- _loc2_++;
- }
- }
-
- private static function init() : void
- {
- var _loc1_:int = 0;
- var _loc2_:String = null;
- var _loc3_:Sound = null;
- var _loc4_:Object = null;
- soundsArr = new Array();
- _loc1_ = 0;
- while(_loc1_ < SOUNDSLINK.length)
- {
- _loc2_ = String(SOUNDSLINK[_loc1_]);
- _loc3_ = getSound(_loc2_);
- (_loc4_ = new Object()).label = _loc2_;
- _loc4_.sound = _loc3_;
- soundsArr.push(_loc4_);
- _loc1_++;
- }
- }
-
- public static function playMusic(param1:String) : void
- {
- var _loc2_:int = 0;
- var _loc3_:Object = null;
- var _loc4_:SoundChannel = null;
- if(enabled)
- {
- _loc2_ = 0;
- while(_loc2_ < soundsArr.length)
- {
- _loc3_ = soundsArr[_loc2_];
- if(_loc3_.label == param1)
- {
- currentMusic = param1;
- _loc4_ = _loc3_.sound.play(0,int.MAX_VALUE,new SoundTransform(VALUEMUSIC));
- _loc3_.channel = _loc4_;
- }
- _loc2_++;
- }
- }
- }
-
- private static function getSound(param1:String) : Sound
- {
- var _loc2_:Class = null;
- var _loc3_:Sound = null;
- _loc2_ = getDefinitionByName(param1) as Class;
- return new _loc2_();
- }
-
- public static function playSound(param1:String) : void
- {
- var _loc2_:int = 0;
- var _loc3_:Object = null;
- var _loc4_:SoundChannel = null;
- if(enabled)
- {
- _loc2_ = 0;
- while(_loc2_ < soundsArr.length)
- {
- _loc3_ = soundsArr[_loc2_];
- if(_loc3_.label == param1)
- {
- _loc4_ = _loc3_.sound.play(0,0,new SoundTransform(VALUESOUND));
- _loc3_.channel = _loc4_;
- }
- _loc2_++;
- }
- }
- }
-
- public static function setEnabled(param1:Boolean) : void
- {
- enabled = param1;
- if(param1)
- {
- playMusic(currentMusic);
- }
- else
- {
- stopMusic();
- }
- }
- }
- }
-