home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Esportes / CrossingCup.swf / scripts / __Packages / SoundManager.as < prev    next >
Text File  |  2007-12-11  |  10KB  |  359 lines

  1. class SoundManager
  2. {
  3.    function SoundManager(_mcRoot)
  4.    {
  5.       this.mcRoot = _root;
  6.    }
  7.    function addSpeaker()
  8.    {
  9.       var _loc3_ = {_x:772.1,_y:1.5};
  10.       this.mcSpeaker = this.mcRoot.attachMovie("speaker","speaker",1000,_loc3_);
  11.       this.mcSpeaker.show();
  12.       this.mcSpeaker.gotoAndStop(1);
  13.       this.mcSpeaker.onMouseDown = function()
  14.       {
  15.          if(this.hitTest(_root._xmouse,_root._ymouse))
  16.          {
  17.             this.toggleSound();
  18.          }
  19.       };
  20.       this.mcSpeaker.toggleSound = function()
  21.       {
  22.          if(this._currentframe == 1)
  23.          {
  24.             this.gotoAndStop(2);
  25.             SoundManager.ins().MusicMute();
  26.          }
  27.          else
  28.          {
  29.             SoundManager.ins().MusicOn();
  30.             this.gotoAndStop(1);
  31.          }
  32.       };
  33.    }
  34.    function loadSounds()
  35.    {
  36.       this.mcRoot.createEmptyMovieClip("mcSoundAll",10000);
  37.       this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound",10000);
  38.       this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound2",10001);
  39.       this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound3",10002);
  40.       this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound4",10003);
  41.       this.bgm = new Sound(this.mcRoot.mcSoundAll.mcSound);
  42.       this.bgm.attachSound("bgm");
  43.       this.ambience = new Sound(this.mcRoot.mcSoundAll.mcSound2);
  44.       this.ambience.attachSound("ambience");
  45.       this.ambience2 = new Sound(this.mcRoot.mcSoundAll.mcSound2);
  46.       this.ambience2.attachSound("oi");
  47.       this.goal = new Sound(this.mcRoot.mcSoundAll.mcSound3);
  48.       this.goal.attachSound("goal");
  49.       this.whistle = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  50.       this.whistle.attachSound("wistleshort");
  51.       this.kick = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  52.       this.kick.attachSound("kick");
  53.       this.an1 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  54.       this.an1.attachSound("an1");
  55.       this.an2 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  56.       this.an2.attachSound("an4");
  57.       this.an3 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  58.       this.an3.attachSound("an3");
  59.       this.an4 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  60.       this.an4.attachSound("an4");
  61.       this.mouseover = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  62.       this.mouseover.attachSound("mouseover");
  63.       this.mousedown = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  64.       this.mousedown.attachSound("mousedown");
  65.       this.heartput = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
  66.       this.heartput.attachSound("heartput");
  67.       this.goalplayed = false;
  68.    }
  69.    function setOverallVolume()
  70.    {
  71.       this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
  72.       this.ambience.setVolume(CSessionManager.ins().sndEffectsVolume);
  73.       this.ambience2.setVolume(CSessionManager.ins().sndEffectsVolume);
  74.       this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
  75.       this.whistle.setVolume(CSessionManager.ins().sndEffectsVolume);
  76.       this.kick.setVolume(CSessionManager.ins().sndEffectsVolume);
  77.       this.mouseover.setVolume(CSessionManager.ins().sndEffectsVolume);
  78.       this.mousedown.setVolume(CSessionManager.ins().sndEffectsVolume);
  79.       this.heartput.setVolume(CSessionManager.ins().sndEffectsVolume);
  80.    }
  81.    function setMusicVolume()
  82.    {
  83.       this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
  84.    }
  85.    function setEffectVolume()
  86.    {
  87.       this.ambience.setVolume(CSessionManager.ins().sndEffectsVolume);
  88.       this.ambience2.setVolume(CSessionManager.ins().sndEffectsVolume);
  89.       this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
  90.       this.whistle.setVolume(CSessionManager.ins().sndEffectsVolume);
  91.       this.kick.setVolume(CSessionManager.ins().sndEffectsVolume);
  92.       this.mouseover.setVolume(CSessionManager.ins().sndEffectsVolume);
  93.       this.mousedown.setVolume(CSessionManager.ins().sndEffectsVolume);
  94.       this.heartput.setVolume(CSessionManager.ins().sndEffectsVolume);
  95.    }
  96.    function playBGM()
  97.    {
  98.       this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
  99.       this.bgm.onSoundComplete = mx.utils.Delegate.create(this,this.completeBGM);
  100.       this.bgm.stop();
  101.       this.bgm.start(0);
  102.       this.loopbgm = true;
  103.    }
  104.    function completeBGM()
  105.    {
  106.       if(this.loopbgm)
  107.       {
  108.          this.bgm.start(0);
  109.       }
  110.    }
  111.    function stopBGM()
  112.    {
  113.       this.bgm.stop();
  114.       this.loopbgm = false;
  115.    }
  116.    function fadeBGM(fadein)
  117.    {
  118.       if(fadein)
  119.       {
  120.          this.playBGM();
  121.          this.bgm.setVolume(0);
  122.          this.ibgm = setInterval(this,"fadinginbgm",100);
  123.       }
  124.       else
  125.       {
  126.          this.ibgm = setInterval(this,"fadingoutbgm",100);
  127.       }
  128.    }
  129.    function fadinginbgm()
  130.    {
  131.       var _loc2_ = this.bgm.getVolume();
  132.       _loc2_ += 5;
  133.       this.bgm.setVolume(_loc2_);
  134.       if(_loc2_ >= CSessionManager.ins().sndMusicVolume)
  135.       {
  136.          _loc2_ = CSessionManager.ins().sndMusicVolume;
  137.          clearInterval(this.ibgm);
  138.       }
  139.    }
  140.    function fadingoutbgm()
  141.    {
  142.       var _loc2_ = this.bgm.getVolume();
  143.       _loc2_ -= 5;
  144.       this.bgm.setVolume(_loc2_);
  145.       if(_loc2_ <= 0)
  146.       {
  147.          _loc2_ = 0;
  148.          clearInterval(this.ibgm);
  149.          this.bgm.stop();
  150.       }
  151.    }
  152.    function playWhistle()
  153.    {
  154.       this.whistle.start();
  155.       this.whistle.onSoundComplete = this.completeWhistle;
  156.    }
  157.    function completeWhistle()
  158.    {
  159.       _global.__DISPATCH({type:"endwhistle"});
  160.    }
  161.    function stopWhistle()
  162.    {
  163.       this.whistle.stop();
  164.    }
  165.    function playKick()
  166.    {
  167.       this.kick.start();
  168.    }
  169.    function stopKick()
  170.    {
  171.       this.kick.stop();
  172.    }
  173.    function playMouseover()
  174.    {
  175.       this.mouseover.start();
  176.    }
  177.    function stopMouseover()
  178.    {
  179.       this.mouseover.stop();
  180.    }
  181.    function playMousedown()
  182.    {
  183.       this.mousedown.start();
  184.    }
  185.    function stopMousedown()
  186.    {
  187.       this.mousedown.stop();
  188.    }
  189.    function playHeartput()
  190.    {
  191.       this.heartput.start();
  192.    }
  193.    function stopHeartput()
  194.    {
  195.       this.heartput.stop();
  196.    }
  197.    function playAmbience2()
  198.    {
  199.       this.ambience2.start(0,2);
  200.    }
  201.    function stopAmbience2()
  202.    {
  203.       this.ambience2.stop();
  204.    }
  205.    function playVictory()
  206.    {
  207.       switch(this.randRange(1,4))
  208.       {
  209.          case 1:
  210.             this.an1.start();
  211.             break;
  212.          case 2:
  213.             this.an2.start();
  214.             break;
  215.          case 3:
  216.             this.an3.start();
  217.             break;
  218.          case 4:
  219.             this.an4.start();
  220.       }
  221.    }
  222.    function stopVictory()
  223.    {
  224.       this.an1.stop();
  225.       this.an2.stop();
  226.       this.an3.stop();
  227.       this.an4.stop();
  228.    }
  229.    function fadinginambience2()
  230.    {
  231.       if(Math.random() < 0.3)
  232.       {
  233.          this.ambience2.start(0,1);
  234.       }
  235.    }
  236.    function fadeAmbience(fadein)
  237.    {
  238.       if(fadein)
  239.       {
  240.          this.ambience.start(0,1000);
  241.          this.ambience.setVolume(0);
  242.          this.iambience = setInterval(this,"fadinginambience",100);
  243.          this.iambience2 = setInterval(this,"fadinginambience2",3000);
  244.       }
  245.       else
  246.       {
  247.          this.iambience = setInterval(this,"fadingoutambience",100);
  248.       }
  249.    }
  250.    function fadinginambience()
  251.    {
  252.       var _loc2_ = this.ambience.getVolume();
  253.       _loc2_ += 5;
  254.       this.ambience.setVolume(_loc2_);
  255.       if(_loc2_ >= CSessionManager.ins().sndEffectsVolume)
  256.       {
  257.          _loc2_ = CSessionManager.ins().sndEffectsVolume;
  258.          clearInterval(this.iambience);
  259.       }
  260.    }
  261.    function fadingoutambience()
  262.    {
  263.       var _loc2_ = this.ambience.getVolume();
  264.       _loc2_ -= 5;
  265.       this.ambience.setVolume(_loc2_);
  266.       if(_loc2_ <= 0)
  267.       {
  268.          _loc2_ = 0;
  269.          clearInterval(this.iambience);
  270.          clearInterval(this.iambience2);
  271.          this.ambience.stop();
  272.       }
  273.    }
  274.    function playGoal()
  275.    {
  276.       this.goalplayed = true;
  277.       this.goal.start();
  278.       this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
  279.    }
  280.    function stopGoal()
  281.    {
  282.       this.goalplayed = false;
  283.       this.goal.stop("goal");
  284.    }
  285.    function fadeGoal(fadein)
  286.    {
  287.       if(fadein)
  288.       {
  289.          this.goalplayed = true;
  290.          this.goal.start(0);
  291.          this.goal.setVolume(0);
  292.       }
  293.       else
  294.       {
  295.          if(this.goal.getVolume() == 0)
  296.          {
  297.             return undefined;
  298.          }
  299.          this.igoal = setInterval(this,"fadingoutgoal",100);
  300.       }
  301.    }
  302.    function fadingingoal()
  303.    {
  304.       var _loc2_ = this.goal.getVolume();
  305.       _loc2_ += 5;
  306.       this.goal.setVolume(_loc2_);
  307.       if(_loc2_ >= 80)
  308.       {
  309.          _loc2_ = 80;
  310.          clearInterval(this.igoal);
  311.       }
  312.    }
  313.    function fadingoutgoal()
  314.    {
  315.       var _loc2_ = this.goal.getVolume();
  316.       _loc2_ -= 10;
  317.       this.goal.setVolume(_loc2_);
  318.       if(_loc2_ <= 0)
  319.       {
  320.          _loc2_ = 0;
  321.          clearInterval(this.igoal);
  322.          this.igoal = undefined;
  323.          this.goal.setVolume(0);
  324.          this.goal.stop("goal");
  325.          this.goalplayed = false;
  326.       }
  327.    }
  328.    function MusicMute()
  329.    {
  330.       this.lastVolM = CSessionManager.ins().sndMusicVolume;
  331.       this.lastVolE = CSessionManager.ins().sndEffectsVolume;
  332.       CSessionManager.ins().sndMusicVolume = 0;
  333.       CSessionManager.ins().sndEffectsVolume = 0;
  334.       this.setMusicVolume();
  335.       this.setEffectVolume();
  336.    }
  337.    function MusicOn()
  338.    {
  339.       CSessionManager.ins().sndMusicVolume = this.lastVolM;
  340.       CSessionManager.ins().sndEffectsVolume = this.lastVolE;
  341.       this.setMusicVolume();
  342.       this.setEffectVolume();
  343.    }
  344.    function randRange(min, max)
  345.    {
  346.       var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
  347.       return _loc1_;
  348.    }
  349.    static function _buildInstance()
  350.    {
  351.       SoundManager._oI = new SoundManager();
  352.       return SoundManager._oI;
  353.    }
  354.    static function ins()
  355.    {
  356.       return !(SoundManager._oI instanceof SoundManager) ? SoundManager._buildInstance() : SoundManager._oI;
  357.    }
  358. }
  359.