1

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].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?

Colin Brogan
  • 728
  • 10
  • 26

3 Answers3

3
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;
}
Bartek
  • 1,986
  • 1
  • 14
  • 21
0

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

Almas Adilbek
  • 4,371
  • 10
  • 58
  • 97
  • hmmm.... doesn't seem to work. No errors, /i'm just not getting any fading. When I trace out the the value of 'loaderClip2[indexNumber].soundTransform.volume' inside function 'updateChannel', I get a bunch of 1's. So somehow that property isn't getting tweened – Colin Brogan Aug 01 '11 at 04:44
-1

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.

Colin Brogan
  • 728
  • 10
  • 26
  • Bartek's answer is better, the problem you faced was that SoundTransform properties modifications are not taken into account, you need to "refresh" the whole soundTransform property. That's why when you want tweenLite to manage the fading of your volume, you have to refresh the soundTransform property in an onUpdate handler (cf Bartek's answer). Actually that's the only difference between this code and the one you originally posted. (I know it's an old post, just making things clear for the new comers). – vitaminwater Apr 12 '13 at 14:20