home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.display.MovieClip;
- import flash.display.SimpleButton;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
-
- public class SoundBar extends Sprite
- {
-
- private static const DROP_CLASS:Class = SoundBar_DROP_CLASS;
-
- private static const RETURN_CLASS:Class = SoundBar_RETURN_CLASS;
-
- public static const SOUND_MULTIPLIER:Number = 1.25;
-
- public static var soundVolume:Number = 1;
-
- private static const EXIT_LEVEL_CLASS:Class = SoundBar_EXIT_LEVEL_CLASS;
-
- private static const MUSIC_CLASS:Class = SoundBar_MUSIC_CLASS;
-
- public static const DROP_SOUND:Sound = new DROP_CLASS();
-
- public static const RETURN_SOUND:Sound = new RETURN_CLASS();
-
- public static var soundMuted:Boolean = false;
-
- public static var musicChannel:SoundChannel = null;
-
- public static var musicVolume:Number = 1;
-
- public static var music:Sound = null;
-
- public static const EXIT_LEVEL_SOUND:Sound = new EXIT_LEVEL_CLASS();
-
- private static const BUTTON_CLICK_CLASS:Class = SoundBar_BUTTON_CLICK_CLASS;
-
- private static const ENTER_LEVEL_CLASS:Class = SoundBar_ENTER_LEVEL_CLASS;
-
- public static const MUSIC_MULTIPLIER:Number = 0.8;
-
- private static const LOCK_CLASS:Class = SoundBar_LOCK_CLASS;
-
- public static var musicMuted:Boolean = false;
-
- private static const CHEAT_MODE_CLASS:Class = SoundBar_CHEAT_MODE_CLASS;
-
- public static const RESET_LEVEL_SOUND:Sound = new END_CLASS();
-
- public static const ENTER_LEVEL_SOUND:Sound = new ENTER_LEVEL_CLASS();
-
- public static const BUTTON_CLICK_SOUND:Sound = new BUTTON_CLICK_CLASS();
-
- private static const END_CLASS:Class = SoundBar_END_CLASS;
-
- private static const PICKUP_CLASS:Class = SoundBar_PICKUP_CLASS;
-
- private static var Gfx:Class = SoundBar_Gfx;
-
- public static const LOCK_SOUND:Sound = new LOCK_CLASS();
-
- public static const CHEAT_MODE_SOUND:Sound = new CHEAT_MODE_CLASS();
-
- public static const VICTORY_SOUND:Sound = RESET_LEVEL_SOUND;
-
- public static const PICKUP_SOUND:Sound = new PICKUP_CLASS();
-
-
- public var soundOnButton:SimpleButton;
-
- public var musicSlider:MovieClip;
-
- public var soundSlider:MovieClip;
-
- public var soundOffButton:SimpleButton;
-
- public var musicOnButton:SimpleButton;
-
- public var musicOffButton:SimpleButton;
-
- public function SoundBar()
- {
- super();
- var _loc1_:Sprite = new Gfx();
- while(_loc1_.numChildren)
- {
- addChild(_loc1_.getChildAt(0));
- }
- soundOnButton = getChildByName("soundOnButton") as SimpleButton;
- soundOffButton = getChildByName("soundOffButton") as SimpleButton;
- musicOnButton = getChildByName("musicOnButton") as SimpleButton;
- musicOffButton = getChildByName("musicOffButton") as SimpleButton;
- soundSlider = getChildByName("soundSlider") as MovieClip;
- musicSlider = getChildByName("musicSlider") as MovieClip;
- soundOnButton.addEventListener(MouseEvent.CLICK,toggleSound,false,0,true);
- soundOffButton.addEventListener(MouseEvent.CLICK,toggleSound,false,0,true);
- musicOnButton.addEventListener(MouseEvent.CLICK,toggleMusic,false,0,true);
- musicOffButton.addEventListener(MouseEvent.CLICK,toggleMusic,false,0,true);
- soundOnButton.visible = false;
- musicOnButton.visible = false;
- soundSlider.buttonMode = true;
- musicSlider.buttonMode = true;
- soundSlider.addEventListener(MouseEvent.MOUSE_DOWN,soundDown,false,0,true);
- musicSlider.addEventListener(MouseEvent.MOUSE_DOWN,musicDown,false,0,true);
- if(Game.cookie.data.soundVolume == undefined)
- {
- soundVolume = 0.8;
- }
- else
- {
- soundVolume = Game.cookie.data.soundVolume;
- }
- if(Game.cookie.data.musicVolume == undefined)
- {
- musicVolume = 0.8;
- }
- else
- {
- musicVolume = Game.cookie.data.musicVolume;
- }
- soundSlider.slider.x = 100 * soundVolume;
- musicSlider.slider.x = 100 * musicVolume;
- setSoundVolume(soundVolume);
- setMusicVolume(musicVolume);
- if(Game.cookie.data.soundMuted)
- {
- toggleSound();
- }
- if(Game.cookie.data.musicMuted)
- {
- toggleMusic();
- }
- }
-
- public static function playSound(param1:Sound, param2:Number = 0) : void
- {
- if(soundMuted || !param1)
- {
- return;
- }
- var _loc3_:SoundChannel = param1.play();
- if(_loc3_)
- {
- _loc3_.soundTransform = new SoundTransform(soundVolume * SOUND_MULTIPLIER,Math.max(-1,Math.min(1,param2)));
- }
- }
-
- public static function playMusic() : void
- {
- if(!musicMuted)
- {
- music = new MUSIC_CLASS();
- musicChannel = music.play(0,9999999999999,new SoundTransform(musicVolume * MUSIC_MULTIPLIER,0));
- }
- }
-
- private function musicMove(param1:MouseEvent = null) : void
- {
- musicSlider.slider.x = Math.max(0,Math.min(100,musicSlider.mouseX));
- setMusicVolume(musicSlider.slider.x / 100);
- }
-
- private function soundDown(param1:MouseEvent) : void
- {
- stage.addEventListener(MouseEvent.MOUSE_UP,soundUp,false,0,true);
- stage.addEventListener(MouseEvent.MOUSE_MOVE,soundMove,false,0,true);
- soundMove();
- }
-
- private function soundUp(param1:MouseEvent) : void
- {
- stage.removeEventListener(MouseEvent.MOUSE_UP,soundUp);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE,soundMove);
- soundMove();
- SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
- }
-
- private function soundMove(param1:MouseEvent = null) : void
- {
- soundSlider.slider.x = Math.max(0,Math.min(100,soundSlider.mouseX));
- setSoundVolume(soundSlider.slider.x / 100);
- }
-
- public function setSoundVolume(param1:Number = -1) : void
- {
- if(param1 == -1)
- {
- return;
- }
- Game.cookie.data.soundVolume = soundVolume = param1;
- if(soundMuted)
- {
- toggleSound();
- SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
- }
- }
-
- public function toggleMusic(param1:MouseEvent = null) : void
- {
- Game.cookie.data.musicMuted = musicMuted = !musicMuted;
- musicSlider.slider.visible = !musicMuted;
- if(!musicMuted)
- {
- musicOffButton.visible = true;
- musicOnButton.visible = false;
- playMusic();
- }
- else
- {
- musicOffButton.visible = false;
- musicOnButton.visible = true;
- if(musicChannel != null)
- {
- musicChannel.stop();
- }
- }
- }
-
- private function musicUp(param1:MouseEvent) : void
- {
- stage.removeEventListener(MouseEvent.MOUSE_UP,musicUp);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE,musicMove);
- musicMove();
- SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
- }
-
- public function toggleSound(param1:MouseEvent = null) : void
- {
- Game.cookie.data.soundMuted = soundMuted = !soundMuted;
- soundSlider.slider.visible = !soundMuted;
- if(!soundMuted)
- {
- soundOffButton.visible = true;
- soundOnButton.visible = false;
- }
- else
- {
- soundOffButton.visible = false;
- soundOnButton.visible = true;
- }
- }
-
- public function setMusicVolume(param1:Number = -1) : void
- {
- if(param1 == -1)
- {
- return;
- }
- Game.cookie.data.musicVolume = musicVolume = param1;
- if(musicChannel != null)
- {
- musicChannel.soundTransform = new SoundTransform(musicVolume * MUSIC_MULTIPLIER,0);
- }
- if(musicMuted)
- {
- toggleMusic();
- SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
- }
- }
-
- private function musicDown(param1:MouseEvent) : void
- {
- stage.addEventListener(MouseEvent.MOUSE_UP,musicUp,false,0,true);
- stage.addEventListener(MouseEvent.MOUSE_MOVE,musicMove,false,0,true);
- musicMove();
- }
- }
- }
-