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

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