Tweening global volume in flash
- Posted by kajyr on June 8th, 2009
- Comment now »
Just a quick reminder on how to shut up the master volume on a flash project. I like a smooth tween to the silence, so I’m using the TweenLite libraries.
private function volumeOff():void {
var sf:SoundTransform = new SoundTransform();
TweenLite.to(sf, 1, {volume:0, onUpdate:applySoundTransform, onUpdateParams:[sf]});
}
private function applySoundTransform(s:SoundTransform):void {
SoundMixer.soundTransform = s;
}
var sf:SoundTransform = new SoundTransform();
TweenLite.to(sf, 1, {volume:0, onUpdate:applySoundTransform, onUpdateParams:[sf]});
}
private function applySoundTransform(s:SoundTransform):void {
SoundMixer.soundTransform = s;
}
The trick here is to tween the volume property of a throw-away SoundTransform object, and on each step of the Tween apply that object as the SoundMixer.soundTransform Object, with an helper function. Note that I’m not going to write the function inside the TweenLite’s partameter list, as it is gross and dirty.
Tweening the volume back to 1 is so easy that I’m not writing it, to not offend anyone.
Do you want to leave a comment?