home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / alex_trax.swf / scripts / __Packages / com / neodelight / std / XSound.as < prev    next >
Encoding:
Text File  |  2007-10-01  |  3.9 KB  |  154 lines

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