home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / FishyHop.swf / scripts / __Packages / manage / SoundManage.as < prev   
Encoding:
Text File  |  2008-09-05  |  7.2 KB  |  283 lines

  1. class manage.SoundManage
  2. {
  3.    var soundList;
  4.    var musicList;
  5.    var isMusicPlay;
  6.    var isSoundPlay;
  7.    var soundMc;
  8.    var soundTime;
  9.    var soundTimeMax;
  10.    var soundObject;
  11.    var onEnterFrame;
  12.    function SoundManage()
  13.    {
  14.       _root.createEmptyMovieClip("mysound_mc",_root.getNextHighestDepth());
  15.       _root.createEmptyMovieClip("mymusic_mc",_root.getNextHighestDepth());
  16.       this.soundList = new Object();
  17.       this.musicList = new Object();
  18.       this.addMusic("main_s");
  19.       if(this.isMusicPlay == undefined)
  20.       {
  21.          this.isMusicPlay = true;
  22.          this.playMusic("main_s",999999);
  23.       }
  24.       if(this.isSoundPlay == undefined)
  25.       {
  26.          this.isSoundPlay = true;
  27.       }
  28.    }
  29.    function addMusicOverTime(str, timeNo, frameNo)
  30.    {
  31.       var _loc2_ = this.musicList[str];
  32.       if(_loc2_)
  33.       {
  34.          _loc2_.sound.soundManage = this;
  35.          _loc2_.sound.soundMc = _loc2_.mc;
  36.          _loc2_.sound.soundMc.soundTimeMax = frameNo;
  37.          _loc2_.sound.onSoundComplete = function()
  38.          {
  39.             this.soundMc.soundObject = this;
  40.             this.soundMc.soundTime = 0;
  41.             this.soundMc.onEnterFrame = function()
  42.             {
  43.                this.soundTime = this.soundTime + 1;
  44.                if(this.soundTime >= this.soundTimeMax)
  45.                {
  46.                   this.soundObject.start(0,1);
  47.                   delete this.onEnterFrame;
  48.                }
  49.             };
  50.          };
  51.       }
  52.    }
  53.    function addSound()
  54.    {
  55.       this.addSound2(this.soundList,arguments);
  56.    }
  57.    function addMusic()
  58.    {
  59.       this.addSound2(this.musicList,arguments);
  60.    }
  61.    function addSound2(list, args)
  62.    {
  63.       var _loc10_ = args.length;
  64.       var _loc6_ = -1;
  65.       while((_loc6_ = _loc6_ + 1) < _loc10_)
  66.       {
  67.          var _loc4_ = args[_loc6_];
  68.          if(typeof _loc4_ == "string")
  69.          {
  70.             var _loc0_ = null;
  71.             var _loc3_ = list[_loc4_] = {};
  72.             var _loc5_ = undefined;
  73.             if(list == this.musicList)
  74.             {
  75.                _loc5_ = _root.mymusic_mc;
  76.             }
  77.             else
  78.             {
  79.                _loc5_ = _root.mysound_mc;
  80.             }
  81.             _loc3_.mc = _loc5_.createEmptyMovieClip(_loc4_ + "_sound",_loc5_.getNextHighestDepth());
  82.             _loc3_.sound = new Sound(_loc3_.mc);
  83.             _loc3_.name = _loc4_;
  84.             _loc3_.sound.attachSound(_loc3_.name);
  85.             var _loc7_ = args[_loc6_ + 1];
  86.             if(typeof _loc7_ == "number")
  87.             {
  88.                _loc3_.vol = this.adjustVolume(_loc7_);
  89.                _loc3_.sound.setVolume(_loc3_.vol);
  90.                _loc6_ = _loc6_ + 1;
  91.             }
  92.             else
  93.             {
  94.                _loc3_.vol = 100;
  95.             }
  96.             trace("σèáσàÑΘƒ│µòê∩╝Ü" + _loc4_ + "Θƒ│ΘçÅΣ╕║∩╝Ü" + _loc3_.sound.getVolume());
  97.          }
  98.       }
  99.    }
  100.    function stopSound()
  101.    {
  102.       this.stopSound2(this.soundList,"stop",arguments);
  103.    }
  104.    function stopMusic()
  105.    {
  106.       this.stopSound2(this.musicList,"volume",arguments);
  107.    }
  108.    function stopMusic2()
  109.    {
  110.       this.stopSound2(this.musicList,"stop",arguments);
  111.    }
  112.    function stopSound2(list, action, args)
  113.    {
  114.       var _loc0_ = null;
  115.       if((_loc0_ = action) !== "stop")
  116.       {
  117.          if(args.length > 0)
  118.          {
  119.             for(var _loc3_ in args)
  120.             {
  121.                list[args[_loc3_]].sound.setVolume(0);
  122.             }
  123.          }
  124.          else
  125.          {
  126.             for(_loc3_ in list)
  127.             {
  128.                list[_loc3_].sound.setVolume(0);
  129.             }
  130.          }
  131.       }
  132.       else if(args.length > 0)
  133.       {
  134.          for(_loc3_ in args)
  135.          {
  136.             list[args[_loc3_]].sound.stop();
  137.          }
  138.       }
  139.       else
  140.       {
  141.          for(_loc3_ in list)
  142.          {
  143.             list[_loc3_].sound.stop();
  144.          }
  145.       }
  146.    }
  147.    function returnSound()
  148.    {
  149.       this.isSoundPlay = true;
  150.       for(var _loc2_ in this.soundList)
  151.       {
  152.          this.soundList[_loc2_].sound.setVolume(this.soundList[_loc2_].vol);
  153.       }
  154.    }
  155.    function returnMusic()
  156.    {
  157.       this.isMusicPlay = true;
  158.       for(var _loc2_ in this.musicList)
  159.       {
  160.          this.musicList[_loc2_].sound.setVolume(this.musicList[_loc2_].vol);
  161.       }
  162.    }
  163.    function adjustVolume(vol)
  164.    {
  165.       if(isNaN(vol))
  166.       {
  167.          return 100;
  168.       }
  169.       if(vol > 100)
  170.       {
  171.          return 100;
  172.       }
  173.       if(vol < 0)
  174.       {
  175.          return 0;
  176.       }
  177.       return vol;
  178.    }
  179.    function setSoundVol()
  180.    {
  181.       this.setSoundVol2(this.soundList,arguments);
  182.    }
  183.    function setMusicVol()
  184.    {
  185.       this.setSoundVol2(this.musicList,arguments);
  186.    }
  187.    function setSoundVol2(list, args)
  188.    {
  189.       var _loc9_ = args.length;
  190.       if(_loc9_ > 0)
  191.       {
  192.          if(_loc9_ == 1)
  193.          {
  194.             var _loc7_ = this.adjustVolume(args[0]);
  195.             for(var _loc4_ in list)
  196.             {
  197.                list[_loc4_].vol = _loc7_;
  198.                list[_loc4_].sound.setVolume(_loc7_);
  199.             }
  200.          }
  201.          else
  202.          {
  203.             _loc4_ = -1;
  204.             while((_loc4_ = _loc4_ + 1) < _loc9_)
  205.             {
  206.                var _loc3_ = args[_loc4_];
  207.                if(typeof _loc3_ == "string")
  208.                {
  209.                   var _loc2_ = list[_loc3_];
  210.                   var _loc6_ = args[_loc4_ + 1];
  211.                   if(typeof _loc6_ == "number")
  212.                   {
  213.                      _loc2_.vol = this.adjustVolume(_loc6_);
  214.                      _loc4_ = _loc4_ + 1;
  215.                   }
  216.                   else
  217.                   {
  218.                      _loc2_.vol = 100;
  219.                   }
  220.                   _loc2_.sound.setVolume(_loc2_.vol);
  221.                }
  222.                trace("Φ«╛τ╜«Θƒ│µòê∩╝Ü" + _loc3_ + "Θƒ│ΘçÅΣ╕║∩╝Ü" + _loc2_.sound.getVolume());
  223.             }
  224.          }
  225.       }
  226.    }
  227.    function playSound()
  228.    {
  229.       if(this.isSoundPlay == true)
  230.       {
  231.          this.playSound2(this.soundList,arguments);
  232.       }
  233.    }
  234.    function playMusic()
  235.    {
  236.       if(this.isMusicPlay == true)
  237.       {
  238.          this.playSound2(this.musicList,arguments);
  239.       }
  240.    }
  241.    function playSound2(list, args)
  242.    {
  243.       var _loc5_ = args[0];
  244.       var _loc2_ = args[1];
  245.       if(isNaN(_loc2_))
  246.       {
  247.          _loc2_ = 1;
  248.       }
  249.       var _loc3_ = args[2];
  250.       var _loc4_ = list[_loc5_];
  251.       _loc4_.sound.start(0,_loc2_);
  252.       if(!isNaN(_loc3_))
  253.       {
  254.          _loc4_.setVolume(this.adjustVolume(_loc3_));
  255.       }
  256.    }
  257.    function isTrueStopSound()
  258.    {
  259.       this.stopSound2(this.soundList,"stop",arguments);
  260.    }
  261.    function isTrueStopMusic()
  262.    {
  263.       this.stopSound2(this.musicList,"stop",arguments);
  264.    }
  265.    function clearSoundAndMusic()
  266.    {
  267.       for(var _loc3_ in _root.mymusic_mc)
  268.       {
  269.          removeMovieClip(_root.mymusic_mc[_loc3_]);
  270.       }
  271.       for(_loc3_ in _root.mysound_mc)
  272.       {
  273.          removeMovieClip(_root.mysound_mc[_loc3_]);
  274.       }
  275.       removeMovieClip(_root.mysound_mc);
  276.       removeMovieClip(_root.mymusic_mc);
  277.       this.soundList = null;
  278.       this.musicList = null;
  279.       delete this.soundList;
  280.       delete this.musicList;
  281.    }
  282. }
  283.