home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / HexiomConnect.swf / scripts / SoundBar.as < prev    next >
Text File  |  2008-08-29  |  9KB  |  273 lines

  1. package
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.display.SimpleButton;
  5.    import flash.display.Sprite;
  6.    import flash.events.MouseEvent;
  7.    import flash.media.Sound;
  8.    import flash.media.SoundChannel;
  9.    import flash.media.SoundTransform;
  10.    
  11.    public class SoundBar extends Sprite
  12.    {
  13.       
  14.       private static const DROP_CLASS:Class = SoundBar_DROP_CLASS;
  15.       
  16.       private static const RETURN_CLASS:Class = SoundBar_RETURN_CLASS;
  17.       
  18.       public static const SOUND_MULTIPLIER:Number = 1.25;
  19.       
  20.       public static var soundVolume:Number = 1;
  21.       
  22.       private static const EXIT_LEVEL_CLASS:Class = SoundBar_EXIT_LEVEL_CLASS;
  23.       
  24.       private static const MUSIC_CLASS:Class = SoundBar_MUSIC_CLASS;
  25.       
  26.       public static const DROP_SOUND:Sound = new DROP_CLASS();
  27.       
  28.       public static const RETURN_SOUND:Sound = new RETURN_CLASS();
  29.       
  30.       public static var soundMuted:Boolean = false;
  31.       
  32.       public static var musicChannel:SoundChannel = null;
  33.       
  34.       public static var musicVolume:Number = 1;
  35.       
  36.       public static var music:Sound = null;
  37.       
  38.       public static const EXIT_LEVEL_SOUND:Sound = new EXIT_LEVEL_CLASS();
  39.       
  40.       private static const BUTTON_CLICK_CLASS:Class = SoundBar_BUTTON_CLICK_CLASS;
  41.       
  42.       private static const ENTER_LEVEL_CLASS:Class = SoundBar_ENTER_LEVEL_CLASS;
  43.       
  44.       public static const MUSIC_MULTIPLIER:Number = 0.8;
  45.       
  46.       private static const LOCK_CLASS:Class = SoundBar_LOCK_CLASS;
  47.       
  48.       public static var musicMuted:Boolean = false;
  49.       
  50.       private static const CHEAT_MODE_CLASS:Class = SoundBar_CHEAT_MODE_CLASS;
  51.       
  52.       public static const RESET_LEVEL_SOUND:Sound = new END_CLASS();
  53.       
  54.       public static const ENTER_LEVEL_SOUND:Sound = new ENTER_LEVEL_CLASS();
  55.       
  56.       public static const BUTTON_CLICK_SOUND:Sound = new BUTTON_CLICK_CLASS();
  57.       
  58.       private static const END_CLASS:Class = SoundBar_END_CLASS;
  59.       
  60.       private static const PICKUP_CLASS:Class = SoundBar_PICKUP_CLASS;
  61.       
  62.       private static var Gfx:Class = SoundBar_Gfx;
  63.       
  64.       public static const LOCK_SOUND:Sound = new LOCK_CLASS();
  65.       
  66.       public static const CHEAT_MODE_SOUND:Sound = new CHEAT_MODE_CLASS();
  67.       
  68.       public static const VICTORY_SOUND:Sound = RESET_LEVEL_SOUND;
  69.       
  70.       public static const PICKUP_SOUND:Sound = new PICKUP_CLASS();
  71.        
  72.       
  73.       public var soundOnButton:SimpleButton;
  74.       
  75.       public var musicSlider:MovieClip;
  76.       
  77.       public var soundSlider:MovieClip;
  78.       
  79.       public var soundOffButton:SimpleButton;
  80.       
  81.       public var musicOnButton:SimpleButton;
  82.       
  83.       public var musicOffButton:SimpleButton;
  84.       
  85.       public function SoundBar()
  86.       {
  87.          super();
  88.          var _loc1_:Sprite = new Gfx();
  89.          while(_loc1_.numChildren)
  90.          {
  91.             addChild(_loc1_.getChildAt(0));
  92.          }
  93.          soundOnButton = getChildByName("soundOnButton") as SimpleButton;
  94.          soundOffButton = getChildByName("soundOffButton") as SimpleButton;
  95.          musicOnButton = getChildByName("musicOnButton") as SimpleButton;
  96.          musicOffButton = getChildByName("musicOffButton") as SimpleButton;
  97.          soundSlider = getChildByName("soundSlider") as MovieClip;
  98.          musicSlider = getChildByName("musicSlider") as MovieClip;
  99.          soundOnButton.addEventListener(MouseEvent.CLICK,toggleSound,false,0,true);
  100.          soundOffButton.addEventListener(MouseEvent.CLICK,toggleSound,false,0,true);
  101.          musicOnButton.addEventListener(MouseEvent.CLICK,toggleMusic,false,0,true);
  102.          musicOffButton.addEventListener(MouseEvent.CLICK,toggleMusic,false,0,true);
  103.          soundOnButton.visible = false;
  104.          musicOnButton.visible = false;
  105.          soundSlider.buttonMode = true;
  106.          musicSlider.buttonMode = true;
  107.          soundSlider.addEventListener(MouseEvent.MOUSE_DOWN,soundDown,false,0,true);
  108.          musicSlider.addEventListener(MouseEvent.MOUSE_DOWN,musicDown,false,0,true);
  109.          if(Game.cookie.data.soundVolume == undefined)
  110.          {
  111.             soundVolume = 0.8;
  112.          }
  113.          else
  114.          {
  115.             soundVolume = Game.cookie.data.soundVolume;
  116.          }
  117.          if(Game.cookie.data.musicVolume == undefined)
  118.          {
  119.             musicVolume = 0.8;
  120.          }
  121.          else
  122.          {
  123.             musicVolume = Game.cookie.data.musicVolume;
  124.          }
  125.          soundSlider.slider.x = 100 * soundVolume;
  126.          musicSlider.slider.x = 100 * musicVolume;
  127.          setSoundVolume(soundVolume);
  128.          setMusicVolume(musicVolume);
  129.          if(Game.cookie.data.soundMuted)
  130.          {
  131.             toggleSound();
  132.          }
  133.          if(Game.cookie.data.musicMuted)
  134.          {
  135.             toggleMusic();
  136.          }
  137.       }
  138.       
  139.       public static function playSound(param1:Sound, param2:Number = 0) : void
  140.       {
  141.          if(soundMuted || !param1)
  142.          {
  143.             return;
  144.          }
  145.          var _loc3_:SoundChannel = param1.play();
  146.          if(_loc3_)
  147.          {
  148.             _loc3_.soundTransform = new SoundTransform(soundVolume * SOUND_MULTIPLIER,Math.max(-1,Math.min(1,param2)));
  149.          }
  150.       }
  151.       
  152.       public static function playMusic() : void
  153.       {
  154.          if(!musicMuted)
  155.          {
  156.             music = new MUSIC_CLASS();
  157.             musicChannel = music.play(0,9999999999999,new SoundTransform(musicVolume * MUSIC_MULTIPLIER,0));
  158.          }
  159.       }
  160.       
  161.       private function musicMove(param1:MouseEvent = null) : void
  162.       {
  163.          musicSlider.slider.x = Math.max(0,Math.min(100,musicSlider.mouseX));
  164.          setMusicVolume(musicSlider.slider.x / 100);
  165.       }
  166.       
  167.       private function soundDown(param1:MouseEvent) : void
  168.       {
  169.          stage.addEventListener(MouseEvent.MOUSE_UP,soundUp,false,0,true);
  170.          stage.addEventListener(MouseEvent.MOUSE_MOVE,soundMove,false,0,true);
  171.          soundMove();
  172.       }
  173.       
  174.       private function soundUp(param1:MouseEvent) : void
  175.       {
  176.          stage.removeEventListener(MouseEvent.MOUSE_UP,soundUp);
  177.          stage.removeEventListener(MouseEvent.MOUSE_MOVE,soundMove);
  178.          soundMove();
  179.          SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
  180.       }
  181.       
  182.       private function soundMove(param1:MouseEvent = null) : void
  183.       {
  184.          soundSlider.slider.x = Math.max(0,Math.min(100,soundSlider.mouseX));
  185.          setSoundVolume(soundSlider.slider.x / 100);
  186.       }
  187.       
  188.       public function setSoundVolume(param1:Number = -1) : void
  189.       {
  190.          if(param1 == -1)
  191.          {
  192.             return;
  193.          }
  194.          Game.cookie.data.soundVolume = soundVolume = param1;
  195.          if(soundMuted)
  196.          {
  197.             toggleSound();
  198.             SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
  199.          }
  200.       }
  201.       
  202.       public function toggleMusic(param1:MouseEvent = null) : void
  203.       {
  204.          Game.cookie.data.musicMuted = musicMuted = !musicMuted;
  205.          musicSlider.slider.visible = !musicMuted;
  206.          if(!musicMuted)
  207.          {
  208.             musicOffButton.visible = true;
  209.             musicOnButton.visible = false;
  210.             playMusic();
  211.          }
  212.          else
  213.          {
  214.             musicOffButton.visible = false;
  215.             musicOnButton.visible = true;
  216.             if(musicChannel != null)
  217.             {
  218.                musicChannel.stop();
  219.             }
  220.          }
  221.       }
  222.       
  223.       private function musicUp(param1:MouseEvent) : void
  224.       {
  225.          stage.removeEventListener(MouseEvent.MOUSE_UP,musicUp);
  226.          stage.removeEventListener(MouseEvent.MOUSE_MOVE,musicMove);
  227.          musicMove();
  228.          SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
  229.       }
  230.       
  231.       public function toggleSound(param1:MouseEvent = null) : void
  232.       {
  233.          Game.cookie.data.soundMuted = soundMuted = !soundMuted;
  234.          soundSlider.slider.visible = !soundMuted;
  235.          if(!soundMuted)
  236.          {
  237.             soundOffButton.visible = true;
  238.             soundOnButton.visible = false;
  239.          }
  240.          else
  241.          {
  242.             soundOffButton.visible = false;
  243.             soundOnButton.visible = true;
  244.          }
  245.       }
  246.       
  247.       public function setMusicVolume(param1:Number = -1) : void
  248.       {
  249.          if(param1 == -1)
  250.          {
  251.             return;
  252.          }
  253.          Game.cookie.data.musicVolume = musicVolume = param1;
  254.          if(musicChannel != null)
  255.          {
  256.             musicChannel.soundTransform = new SoundTransform(musicVolume * MUSIC_MULTIPLIER,0);
  257.          }
  258.          if(musicMuted)
  259.          {
  260.             toggleMusic();
  261.             SoundBar.playSound(SoundBar.BUTTON_CLICK_SOUND,mouseX / Game.MIDX - 1);
  262.          }
  263.       }
  264.       
  265.       private function musicDown(param1:MouseEvent) : void
  266.       {
  267.          stage.addEventListener(MouseEvent.MOUSE_UP,musicUp,false,0,true);
  268.          stage.addEventListener(MouseEvent.MOUSE_MOVE,musicMove,false,0,true);
  269.          musicMove();
  270.       }
  271.    }
  272. }
  273.