I've looked around the net on this issue, and came up with the following code to fade out the volume on my movieclip:
var myTransform = new SoundTransform();
myTransform.volume = 1;
loaderClip2[indexNumber].开发者_Python百科soundTransform = myTransform;
audioTween = new TweenLite(myTransform, 2, {volume:0});
My movie clip is stored in the Array loaderClip2
at index position determined by the variable indexNumber
. This code does not produce the desired fade. Can anyone see what is the problem here?
var myTransform:SoundTransform = new SoundTransform(1);
TweenLite.to(myTransform, 1, {volume:0, onUpdate:updateChannel, onUpdateParams:[indexNumber]});
function updateChannel(index:int):void {
loaderClip2[index].soundTransform = myTransform;
}
Try this code:
private function updateChannel() : void {
var st : SoundTransform = new SoundTransform(loaderClip2[indexNumber].soundTransform.volume, 0 );
loaderClip2[indexNumber].soundTransform = st;
}
TweenLite.to(loaderClip2[indexNumber], 4, { volume:.5, ease:Strong.easeInOut, onUpdate:updateChannel } );
Set your own parameters
Alright guys, after trying everything possible with tweenlite, I figured out another solution using good-old-fashioned ENTER_FRAME
events. This is as straight-forward as possible, wish I had thought of it before:
so in a previous function I just do this:
myClip.addEventListener(Event.ENTER_FRAME, fadeAudio);
and then later flush out the event function (or whatever it is called):
var audioshift = 1;
function fadeAudio(e : Event) : void {
audioshift -= .05;
if (audioshift <= 0) {
audioshift = 0;
trace("fadeAudio complete");
e.target.removeEventListener(Event.ENTER_FRAME, fadeAudio);
}
var st : SoundTransform = new SoundTransform(audioshift, 0);
e.target.soundTransform = st;
}
Easy as pie.
精彩评论