home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / starisland.swf / scripts / __Packages / illusoft / utils / Sounds.as < prev   
Encoding:
Text File  |  2007-12-10  |  5.7 KB  |  222 lines

  1. class illusoft.utils.Sounds
  2. {
  3.    var dmc;
  4.    var sounds;
  5.    var soundsmc;
  6.    var start;
  7.    var currentMusicName;
  8.    var onEnterFrame;
  9.    var isPlaying;
  10.    var soundEnabled = true;
  11.    function Sounds(mc)
  12.    {
  13.       this.dmc = mc.createEmptyMovieClip("sounds",mc.getNextHighestDepth());
  14.       this.Init();
  15.    }
  16.    function CreateSound(soundName)
  17.    {
  18.       var _loc2_ = this.dmc.createEmptyMovieClip(soundName,this.dmc.getNextHighestDepth());
  19.       _loc2_.isPlaying = false;
  20.       var _loc3_ = new Sound(_loc2_);
  21.       _loc3_.attachSound("snd_" + soundName);
  22.       this.sounds[soundName] = _loc3_;
  23.       this.soundsmc[soundName] = _loc2_;
  24.    }
  25.    function Init()
  26.    {
  27.       this.sounds = new Array();
  28.       this.soundsmc = new Array();
  29.       this.CreateSound("child");
  30.       this.CreateSound("jetstream");
  31.       this.CreateSound("bling");
  32.       this.CreateSound("surprise");
  33.       this.CreateSound("jippie");
  34.       this.CreateSound("jippie2");
  35.       this.CreateSound("door");
  36.       this.CreateSound("explode");
  37.       this.CreateSound("boing");
  38.       this.CreateSound("loop0");
  39.       this.CreateSound("loop1");
  40.       this.CreateSound("loop2");
  41.       this.CreateSound("loop3");
  42.       this.CreateSound("loop4");
  43.       this.CreateSound("map");
  44.       this.CreateSound("victory");
  45.       this.CreateSound("game_over");
  46.       this.CreateSound("water");
  47.       this.CreateSound("hit");
  48.       this.CreateSound("waterpao");
  49.       this.CreateSound("boing2");
  50.       this.CreateSound("boing3");
  51.       this.CreateSound("stoneboing");
  52.       this.CreateSound("stonemove");
  53.       this.CreateSound("win");
  54.       this.CreateSound("niao");
  55.       this.CreateSound("snow");
  56.       this.CreateSound("over");
  57.       this.CreateSound("timeout");
  58.       this.CreateSound("in");
  59.       this.CreateSound("fei");
  60.       this.CreateSound("bee");
  61.       this.CreateSound("bs");
  62.       this.CreateSound("x");
  63.       this.CreateSound("sw");
  64.       this.CreateSound("fc");
  65.       this.CreateSound("ju");
  66.    }
  67.    function PlaySound(soundName, Volume)
  68.    {
  69.       if(Volume == null)
  70.       {
  71.          Volume = 100;
  72.       }
  73.       if(this.soundEnabled)
  74.       {
  75.          var _loc3_ = this.soundsmc[soundName];
  76.          _loc3_.onEnterFrame = null;
  77.          var _loc2_ = this.sounds[soundName];
  78.          _loc2_.stop();
  79.          _loc2_.setVolume(Volume);
  80.          _loc2_.start(0,1);
  81.       }
  82.    }
  83.    function StopSound(soundName)
  84.    {
  85.       var _loc3_ = this.sounds[soundName];
  86.       var _loc2_ = this.soundsmc[soundName];
  87.       _loc3_.stop();
  88.       _loc2_.isPlaying = false;
  89.    }
  90.    function LoopSound(soundName, Volume)
  91.    {
  92.       if(Volume == null)
  93.       {
  94.          Volume = 100;
  95.       }
  96.       if(this.soundEnabled)
  97.       {
  98.          var _loc3_ = this.sounds[soundName];
  99.          var _loc2_ = this.soundsmc[soundName];
  100.          if(!_loc2_.isPlaying)
  101.          {
  102.             _loc2_.isPlaying = true;
  103.             _loc3_.start(0,1);
  104.             _loc3_.onSoundComplete = function()
  105.             {
  106.                this.start(0,1);
  107.             };
  108.          }
  109.          else
  110.          {
  111.             this.FadeVolume(soundName,true,false,3,Volume);
  112.          }
  113.       }
  114.    }
  115.    function StartMusic(musicName, Volume)
  116.    {
  117.       if(Volume == null)
  118.       {
  119.          Volume = 70;
  120.       }
  121.       this.FadeMusic();
  122.       if(this.soundEnabled)
  123.       {
  124.          var _loc3_ = this.soundsmc[musicName];
  125.          _loc3_.onEnterFrame = null;
  126.          var _loc2_ = this.sounds[musicName];
  127.          _loc2_.stop();
  128.          _loc2_.setVolume(Volume);
  129.          _loc2_.start(0,999);
  130.       }
  131.       this.currentMusicName = musicName;
  132.    }
  133.    function FadeMusic()
  134.    {
  135.       if(this.currentMusicName != null)
  136.       {
  137.          this.sounds[this.currentMusicName].stop();
  138.          this.currentMusicName = null;
  139.       }
  140.    }
  141.    function FadeAllMusic()
  142.    {
  143.       if(this.currentMusicName != null)
  144.       {
  145.          this.FadeVolume(this.currentMusicName,false,false,1);
  146.          this.currentMusicName = null;
  147.       }
  148.    }
  149.    function ToggleSound(mc)
  150.    {
  151.       this.soundEnabled = !this.soundEnabled;
  152.       if(this.soundEnabled)
  153.       {
  154.          mc.gotoAndStop("on");
  155.          if(this.currentMusicName != null)
  156.          {
  157.             this.StartMusic(this.currentMusicName);
  158.          }
  159.       }
  160.       else
  161.       {
  162.          mc.gotoAndStop("off");
  163.          for(var _loc2_ in this.sounds)
  164.          {
  165.             this.FadeVolume(_loc2_,false,false,null);
  166.          }
  167.       }
  168.    }
  169.    function FadeVolume(soundName, louder, fromStart, speed, Volume)
  170.    {
  171.       if(speed == null)
  172.       {
  173.          speed = 3;
  174.       }
  175.       if(Volume == null)
  176.       {
  177.          Volume = 100;
  178.       }
  179.       var snd = this.sounds[soundName];
  180.       var _loc2_ = this.soundsmc[soundName];
  181.       if(fromStart)
  182.       {
  183.          if(louder)
  184.          {
  185.             snd.setVolume(1);
  186.             snd.start(0,1);
  187.             _loc2_.isPlaying = true;
  188.          }
  189.          else
  190.          {
  191.             snd.setVolume(Volume - 1);
  192.          }
  193.       }
  194.       if(louder)
  195.       {
  196.          _loc2_.onEnterFrame = function()
  197.          {
  198.             snd.setVolume(snd.getVolume() + speed);
  199.             if(snd.getVolume() >= Volume - 1)
  200.             {
  201.                snd.setVolume(Volume);
  202.                delete this.onEnterFrame;
  203.             }
  204.          };
  205.       }
  206.       else
  207.       {
  208.          _loc2_.onEnterFrame = function()
  209.          {
  210.             snd.setVolume(snd.getVolume() - speed);
  211.             if(snd.getVolume() <= 0)
  212.             {
  213.                snd.stop();
  214.                snd.setVolume(Volume);
  215.                this.isPlaying = false;
  216.                delete this.onEnterFrame;
  217.             }
  218.          };
  219.       }
  220.    }
  221. }
  222.