home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / midnightstrike1.swf / scripts / __Packages / com / neodelight / std / XSound.as < prev    next >
Encoding:
Text File  |  2007-04-02  |  3.2 KB  |  129 lines

  1. class com.neodelight.std.XSound extends Sound
  2. {
  3.    var channels;
  4.    var groups;
  5.    var master;
  6.    var channelsAmount = 8;
  7.    function XSound()
  8.    {
  9.       super();
  10.       this.channels = new Array(this.channelsAmount);
  11.       this.groups = {fx:1,music:1};
  12.       var _loc4_ = 0;
  13.       while(_loc4_ < this.channelsAmount)
  14.       {
  15.          this.channels[_loc4_] = new com.neodelight.std.XSoundChannel(_loc4_,_root.createEmptyMovieClip(com.neodelight.std.Unique.getKey(),_root.getNextHighestDepth()),this.groups);
  16.          _loc4_ = _loc4_ + 1;
  17.       }
  18.       this.master = new Sound();
  19.       this.master.setVolume(100);
  20.    }
  21.    function addGroup(id)
  22.    {
  23.       this.groups[id] = 1;
  24.    }
  25.    function setVolume(volume)
  26.    {
  27.       this.master.setVolume(volume * 100);
  28.    }
  29.    function getVolume()
  30.    {
  31.       return this.master.getVolume() * 0.01;
  32.    }
  33.    function setGroupVolume(volume, id)
  34.    {
  35.       this.groups[id] = volume;
  36.       var _loc2_ = this.channels.length;
  37.       while(_loc2_--)
  38.       {
  39.          this.channels[_loc2_].setVolume();
  40.       }
  41.    }
  42.    function getGroupVolume(id)
  43.    {
  44.       return this.groups[id];
  45.    }
  46.    function playLoop(libId, volume, group)
  47.    {
  48.       var _loc2_ = this.getChannel();
  49.       _loc2_.attachSound(libId);
  50.       _loc2_.start(0,99999);
  51.       _loc2_.group = !group ? "music" : group;
  52.       _loc2_.setVolume(volume);
  53.       _loc2_.libId = libId;
  54.       _loc2_.locked = true;
  55.       _loc2_.playing = true;
  56.       return _loc2_;
  57.    }
  58.    function playEvent(libId, volume, group)
  59.    {
  60.       trace("snd: " + libId);
  61.       var _loc2_ = this.getChannel();
  62.       _loc2_.attachSound(libId);
  63.       _loc2_.start(0,0);
  64.       _loc2_.group = !group ? "fx" : group;
  65.       _loc2_.setVolume(volume);
  66.       _loc2_.libId = libId;
  67.       _loc2_.playing = true;
  68.       return _loc2_;
  69.    }
  70.    function getChannel()
  71.    {
  72.       var _loc4_ = -1;
  73.       var _loc5_ = -1;
  74.       var _loc3_ = 0;
  75.       while(_loc3_ < this.channels.length)
  76.       {
  77.          var _loc2_ = this.channels[_loc3_];
  78.          if(!_loc2_.locked)
  79.          {
  80.             if(!_loc2_.playing)
  81.             {
  82.                return this.channels[_loc3_];
  83.             }
  84.             if(_loc2_.position > _loc4_)
  85.             {
  86.                _loc4_ = _loc2_.position;
  87.                _loc5_ = _loc2_.id;
  88.             }
  89.          }
  90.          _loc3_ = _loc3_ + 1;
  91.       }
  92.       if(_loc5_ != -1)
  93.       {
  94.          return this.channels[_loc5_];
  95.       }
  96.    }
  97.    function fadeChannel(channel, fadeTo, time)
  98.    {
  99.       if(fadeTo < 0)
  100.       {
  101.          channel.fadeOutFlag = true;
  102.          fadeTo = 0;
  103.       }
  104.       if(time <= 0)
  105.       {
  106.          channel.setVolume(fadeTo * 100);
  107.          channel.fading = false;
  108.       }
  109.       else
  110.       {
  111.          channel.fading = true;
  112.          channel.fadeTo = Math.min(100,fadeTo * 100);
  113.          channel.fadeSpeed = (fadeTo - channel.getVolume()) / time;
  114.       }
  115.    }
  116.    function stop(libId)
  117.    {
  118.       var _loc2_ = 0;
  119.       while(_loc2_ < this.channels.length)
  120.       {
  121.          if(this.channels[_loc2_].libId == libId || !libId)
  122.          {
  123.             this.channels[_loc2_].stop();
  124.          }
  125.          _loc2_ = _loc2_ + 1;
  126.       }
  127.    }
  128. }
  129.