Volume Tweener

Hello,

I’m working on a custom tween class. Everything work good, instead of sound volume.

I’m using the following code:

package {
	import flash.events.Event;
	import flash.media.SoundTransform;
	import flash.media.SoundChannel;
	
	public class easePH_AS3{
		//LINEAR EASING//
		private static function linearTween(t:Number, b:Number, c:Number, d:Number):Number {
            return c*t/d + b;
		}
///////////////////////////////
//SOUND TWEEN FUNCTION
//////////////////////////////
		public static function VolumeTween_Linear(sC:SoundChannel,sT:SoundTransform,t:Number,d:Number,fvol:Number):void{
    		sT.volume = fvol;
    		var bvol:Number = sC.soundTransform.volume;
    		var cvol:Number = fvol - bvol;
    		function LinearVolumeTween(event:Event):void{
    			if(t++ < d){
    				sT.volume = linearTween(t,bvol,cvol,d);
    				sC.soundTransform = sT;
     			}
    		}
    		sC.addEventListener(Event.ENTER_FRAME,LinearVolumeTween)
		}
	}	
}

and the usage of these class will be:

someSound = new Sound(new URLRequest("sound.mp3"));
someChannel = new SoundChannel();
someTransform = new SoundTransform();
someTransform.volume = 1;
someChannel = someSound.play(0,0,someTransform);
trace("start volume: " + someChannel.soundTransform.volume);

//checkbox control function
private function volumeFade():void{
		if(chk.selected == true){
			easePH_AS3.VolumeTween_Linear(someChannel,someTransform,0,30,1);
			trace("up transformed volume: " + someChannel.soundTransform.volume);
		}else{
			easePH_AS3.VolumeTween_Linear(someChannel,someTransform,0,30,0);
			trace("down transformed volume: " + someChannel.soundTransform.volume);
		}
	}

It seems that if I use the ENTER_FRAME event for transformation nothing happens.

How to solve this problem?

Thanks in advance,
Nikola

You don’t have to reinvent the wheel, tweenlite or tweenmax will do this:

TweenLite.to(yourTransform, 1, {volume:0, onUpdate:updateChannelFunction, onComplete:stopSoundFunction});