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

  1. class com.neodelight.std.XSoundChannel extends Sound
  2. {
  3.    var id;
  4.    var playing;
  5.    var locked;
  6.    var groups;
  7.    var mc;
  8.    var channel;
  9.    var volume;
  10.    var group;
  11.    var fadeOutFlag;
  12.    var fading;
  13.    var fadeTo;
  14.    var fadeSpeed;
  15.    var sequence;
  16.    var sequencePointer;
  17.    var libId;
  18.    var sequenceStep;
  19.    var channelId;
  20.    function XSoundChannel(id, mc, groups)
  21.    {
  22.       super(mc);
  23.       this.id = id;
  24.       this.playing = false;
  25.       this.locked = false;
  26.       this.groups = groups;
  27.       this.mc = mc;
  28.       this.mc.channel = this;
  29.       this.mc.onEnterFrame = function()
  30.       {
  31.          if(!this.channel.fading)
  32.          {
  33.             return undefined;
  34.          }
  35.          var _loc2_ = this.channel.getVolume() + this.channel.fadeSpeed;
  36.          _loc2_ = this.channel.fadeSpeed <= 0 ? Math.max(this.channel.fadeTo,_loc2_) : Math.min(this.channel.fadeTo,_loc2_);
  37.          if(_loc2_ == this.channel.fadeTo)
  38.          {
  39.             this.channel.fading = false;
  40.             if(this.channel.fadeOutFlag)
  41.             {
  42.                this.channel.stop();
  43.             }
  44.          }
  45.          this.channel.setVolume(_loc2_);
  46.       };
  47.    }
  48.    function setVolume(volume)
  49.    {
  50.       if(volume != undefined)
  51.       {
  52.          this.volume = volume;
  53.       }
  54.       super.setVolume(Math.max(0,Math.min(100,this.volume * 100 * this.groups[this.group])));
  55.    }
  56.    function getVolume()
  57.    {
  58.       return this.volume;
  59.    }
  60.    function fade(fadeTo, frames)
  61.    {
  62.       if(fadeTo == -1)
  63.       {
  64.          this.fadeOutFlag = true;
  65.          fadeTo = 0;
  66.       }
  67.       else
  68.       {
  69.          this.fadeOutFlag = false;
  70.       }
  71.       if(frames <= 0)
  72.       {
  73.          this.setVolume(fadeTo);
  74.          this.fading = false;
  75.       }
  76.       else
  77.       {
  78.          this.fading = true;
  79.          this.fadeTo = Math.min(1,fadeTo);
  80.          this.fadeSpeed = (fadeTo - this.getVolume()) / frames;
  81.       }
  82.    }
  83.    function playSequence(sequence, locked, group)
  84.    {
  85.       this.sequence = sequence;
  86.       this.sequencePointer = 0;
  87.       this.locked = locked;
  88.       this.fading = false;
  89.       this.group = !group ? "fx" : group;
  90.       this.playing = true;
  91.       this.stepSequence();
  92.       this.onSoundComplete = this.stepSequence;
  93.       this.libId = "__SEQUENCE__";
  94.    }
  95.    function stepSequence()
  96.    {
  97.       if(this.sequenceStep.goto != undefined)
  98.       {
  99.          this.sequencePointer = this.sequenceStep.goto;
  100.       }
  101.       var _loc2_ = this.sequence[this.sequencePointer++];
  102.       this.sequenceStep = _loc2_;
  103.       if(!_loc2_)
  104.       {
  105.          this.stop();
  106.       }
  107.       if(_loc2_.times == 0)
  108.       {
  109.          _loc2_.times = 9999;
  110.          _loc2_.goto = this.sequencePointer - 1;
  111.       }
  112.       else if(_loc2_.times == undefined)
  113.       {
  114.          _loc2_.times = 1;
  115.       }
  116.       this.attachSound(_loc2_.id);
  117.       this.setVolume(_loc2_.vol);
  118.       this.start(!_loc2_.offset ? 0 : _loc2_.offset,_loc2_.times);
  119.       if(_loc2_.fadeFrames)
  120.       {
  121.          this.fade(_loc2_.fadeTo,_loc2_.fadeFrames);
  122.       }
  123.    }
  124.    function stop()
  125.    {
  126.       this.onSoundComplete = undefined;
  127.       this.sequenceStep = undefined;
  128.       this.locked = false;
  129.       this.playing = false;
  130.       this.fading = false;
  131.       if(this.channelId)
  132.       {
  133.          delete _global.snd.channelsById[this.channelId];
  134.       }
  135.       super.stop();
  136.    }
  137.    function onSoundComplete()
  138.    {
  139.       this.playing = false;
  140.       this.locked = false;
  141.       this.fading = false;
  142.    }
  143.    function toString()
  144.    {
  145.       return "v:" + this.getVolume() + " p:" + this.playing + " l:" + this.locked + " f:" + this.fading + " lib:" + this.libId;
  146.    }
  147. }
  148.