home *** CD-ROM | disk | FTP | other *** search
- package ENGINE.CORE
- {
- import flash.events.Event;
- import flash.events.IOErrorEvent;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.net.URLRequest;
- import flash.utils.Dictionary;
-
- public class OSound
- {
-
- private static var iMusicInd:int = 0;
-
- private static var iSoundsObjects:Array;
-
- private static var iSounds:Dictionary = new Dictionary(true);
-
- private static var iMusicPlayList:Array = new Array();
-
- private static var iSoundVolume:Number = 1;
-
- private static var iMusicChannel:SoundChannel;
-
- private static var iMusicVolume:Number = 1;
-
- private static var iMusic:Sound;
-
-
- public function OSound()
- {
- super();
- }
-
- public static function PlaySoundInd(param1:int, param2:Number = 0) : Boolean
- {
- if(OSound.iSoundVolume == 0)
- {
- return false;
- }
- param1 = Math.max(param1,0);
- param1 = Math.min(param1,OSound.iSoundsObjects.length - 1);
- return OSound.PlaySound(OSound.iSoundsObjects[param1],param2);
- }
-
- public static function set MusicVolume(param1:Number) : void
- {
- var _loc2_:SoundTransform = null;
- OSound.iMusicVolume = param1;
- if(OSound.iMusicChannel)
- {
- if(param1 == 0)
- {
- OSound.StopMusic();
- }
- else
- {
- _loc2_ = OSound.iMusicChannel.soundTransform;
- _loc2_.volume = param1;
- OSound.iMusicChannel.soundTransform = _loc2_;
- }
- }
- else if(OSound.iMusicVolume > 0)
- {
- OSound.PlayMusic();
- }
- }
-
- private static function OnMusicLoadComplete(param1:Event) : void
- {
- if(OSound.iMusicVolume == 0)
- {
- return;
- }
- OSound.iMusicChannel = iMusic.play(0,0,new SoundTransform(OSound.iMusicVolume,0));
- OSound.RemoveMusic();
- OSound.iMusicChannel.addEventListener(Event.SOUND_COMPLETE,OnMusicComplete);
- }
-
- public static function set SoundVolume(param1:Number) : void
- {
- OSound.iSoundVolume = param1;
- }
-
- private static function OnMusicLoadIOError(param1:Event) : void
- {
- OSound.RemoveMusic();
- OSound.iMusicPlayList.splice(OSound.iMusicInd,1);
- OSound.iMusicInd = OSound.iMusicInd > OSound.iMusicPlayList.length - 1 ? int(OSound.iMusicPlayList.length - 1) : OSound.iMusicInd;
- OSound.PlayMusic();
- }
-
- private static function OnMusicComplete(param1:Event) : void
- {
- PlayMusic();
- }
-
- public static function PlaySound(param1:Class, param2:Number = 0) : Boolean
- {
- var _loc3_:Sound = null;
- if(OSound.iSoundVolume == 0)
- {
- return false;
- }
- _loc3_ = OSound.iSounds[param1];
- if(_loc3_ != null)
- {
- _loc3_.play(0,0,new SoundTransform(OSound.iSoundVolume,param2));
- }
- return _loc3_ != null;
- }
-
- private static function RemoveMusic() : void
- {
- if(OSound.iMusic)
- {
- OSound.iMusic.removeEventListener(Event.COMPLETE,OSound.OnMusicLoadComplete);
- OSound.iMusic.removeEventListener(IOErrorEvent.IO_ERROR,OSound.OnMusicLoadIOError);
- OSound.iMusic = null;
- }
- }
-
- public static function StopMusic() : void
- {
- if(OSound.iMusicChannel)
- {
- OSound.iMusicChannel.removeEventListener(Event.SOUND_COMPLETE,OnMusicComplete);
- OSound.iMusicChannel.stop();
- OSound.iMusicChannel = null;
- }
- }
-
- public static function get SoundVolume() : Number
- {
- return OSound.iSoundVolume;
- }
-
- public static function PlayListClear() : void
- {
- OSound.iMusicPlayList = new Array();
- }
-
- public static function PlayListAdd(param1:String) : void
- {
- OSound.iMusicPlayList.push(param1);
- OSound.iMusicInd = OSound.iMusicPlayList.length - 1;
- }
-
- public static function PlayMusic() : void
- {
- var request:URLRequest = null;
- if(OSound.iMusicVolume == 0 || !OSound.iMusicPlayList.length)
- {
- return;
- }
- OSound.StopMusic();
- OSound.iMusicInd = (OSound.iMusicInd + 1) % OSound.iMusicPlayList.length;
- request = new URLRequest(OSound.iMusicPlayList[OSound.iMusicInd]);
- OSound.iMusic = new Sound();
- OSound.iMusic.addEventListener(Event.COMPLETE,OSound.OnMusicLoadComplete);
- OSound.iMusic.addEventListener(IOErrorEvent.IO_ERROR,OSound.OnMusicLoadIOError);
- try
- {
- OSound.iMusic.load(request);
- }
- catch(e:Error)
- {
- }
- }
-
- public static function RegisterEmbedSounds(param1:Array) : Boolean
- {
- var _loc2_:int = 0;
- var _loc3_:Sound = null;
- OSound.iSoundsObjects = param1;
- _loc2_ = 0;
- while(_loc2_ < param1.length)
- {
- _loc3_ = new param1[_loc2_]() as Sound;
- OSound.iSounds[param1[_loc2_]] = _loc3_;
- _loc2_++;
- }
- return true;
- }
-
- public static function PlaySoundRandom(param1:Number = 0, param2:int = 0, param3:int = -1) : Boolean
- {
- var _loc4_:int = 0;
- if(OSound.iSoundVolume == 0)
- {
- return false;
- }
- param2 = Math.max(param2,0);
- param2 = Math.min(param2,OSound.iSoundsObjects.length - 1);
- if(param3 < 0)
- {
- param3 = int(OSound.iSoundsObjects.length - 1);
- }
- param3 = Math.max(param3,0);
- param3 = Math.min(param3,OSound.iSoundsObjects.length - 1);
- _loc4_ = OUtils.Random(param2,param3);
- return OSound.PlaySound(OSound.iSoundsObjects[_loc4_],param1);
- }
-
- public static function get MusicVolume() : Number
- {
- return OSound.iMusicVolume;
- }
- }
- }
-