home *** CD-ROM | disk | FTP | other *** search
- class com.neodelight.std.XSoundChannel extends Sound
- {
- var id;
- var playing;
- var locked;
- var groups;
- var mc;
- var channel;
- var volume;
- var group;
- var fadeOutFlag;
- var fading;
- var fadeTo;
- var fadeSpeed;
- var sequence;
- var sequencePointer;
- var libId;
- var sequenceStep;
- var channelId;
- function XSoundChannel(id, mc, groups)
- {
- super(mc);
- this.id = id;
- this.playing = false;
- this.locked = false;
- this.groups = groups;
- this.mc = mc;
- this.mc.channel = this;
- this.mc.onEnterFrame = function()
- {
- if(!this.channel.fading)
- {
- return undefined;
- }
- var _loc2_ = this.channel.getVolume() + this.channel.fadeSpeed;
- _loc2_ = this.channel.fadeSpeed <= 0 ? Math.max(this.channel.fadeTo,_loc2_) : Math.min(this.channel.fadeTo,_loc2_);
- if(_loc2_ == this.channel.fadeTo)
- {
- this.channel.fading = false;
- if(this.channel.fadeOutFlag)
- {
- this.channel.stop();
- }
- }
- this.channel.setVolume(_loc2_);
- };
- }
- function setVolume(volume)
- {
- if(volume != undefined)
- {
- this.volume = volume;
- }
- super.setVolume(Math.max(0,Math.min(100,this.volume * 100 * this.groups[this.group])));
- }
- function getVolume()
- {
- return this.volume;
- }
- function fade(fadeTo, frames)
- {
- if(fadeTo == -1)
- {
- this.fadeOutFlag = true;
- fadeTo = 0;
- }
- else
- {
- this.fadeOutFlag = false;
- }
- if(frames <= 0)
- {
- this.setVolume(fadeTo);
- this.fading = false;
- }
- else
- {
- this.fading = true;
- this.fadeTo = Math.min(1,fadeTo);
- this.fadeSpeed = (fadeTo - this.getVolume()) / frames;
- }
- }
- function playSequence(sequence, locked, group)
- {
- this.sequence = sequence;
- this.sequencePointer = 0;
- this.locked = locked;
- this.fading = false;
- this.group = !group ? "fx" : group;
- this.playing = true;
- this.stepSequence();
- this.onSoundComplete = this.stepSequence;
- this.libId = "__SEQUENCE__";
- }
- function stepSequence()
- {
- if(this.sequenceStep.goto != undefined)
- {
- this.sequencePointer = this.sequenceStep.goto;
- }
- var _loc2_ = this.sequence[this.sequencePointer++];
- this.sequenceStep = _loc2_;
- if(!_loc2_)
- {
- this.stop();
- }
- if(_loc2_.times == 0)
- {
- _loc2_.times = 9999;
- _loc2_.goto = this.sequencePointer - 1;
- }
- else if(_loc2_.times == undefined)
- {
- _loc2_.times = 1;
- }
- this.attachSound(_loc2_.id);
- this.setVolume(_loc2_.vol);
- this.start(!_loc2_.offset ? 0 : _loc2_.offset,_loc2_.times);
- if(_loc2_.fadeFrames)
- {
- this.fade(_loc2_.fadeTo,_loc2_.fadeFrames);
- }
- }
- function stop()
- {
- this.onSoundComplete = undefined;
- this.sequenceStep = undefined;
- this.locked = false;
- this.playing = false;
- this.fading = false;
- if(this.channelId)
- {
- delete _global.snd.channelsById[this.channelId];
- }
- super.stop();
- }
- function onSoundComplete()
- {
- this.playing = false;
- this.locked = false;
- this.fading = false;
- }
- function toString()
- {
- return "v:" + this.getVolume() + " p:" + this.playing + " l:" + this.locked + " f:" + this.fading + " lib:" + this.libId;
- }
- }
-