Search code examples
actionscript-3flash-cs4

Slow Down Playback of a MovieClip


I am trying to gradually slow down a movie clip using Actionscript 3. My current code plays the movie clip and then abruptly stops and ticks ahead a few frames. A much rougher look than I want.

var t:Timer=new Timer(2000,1);
t.addEventListener(TimerEvent.TIMER,slowDown);
t.start();

function slowDown(e:TimerEvent):void {

    if (currentFrame==totalFrames) {
        gotoAndStop(1);

    } else {

       gotoAndStop(currentFrame+1);
    }
}

Is the Timer class at least the right direction? Thanks.


Solution

  • Sounds to me like you want to employ the power of a Tweening Engine - there are quite a few of them out there, but my favourite is Greensock TweenMax.

    The following code will tween the playhead of a MovieClip gradually slowing down (easing) as it nears the end of playback:

    import com.greensock.*;
    import com.greensock.easing.*;
    
    TweenMax.to(myMovieClip, 2, { frame: myMovieClip.totalFrames, ease: Expo.easeOut });