KONY 2012 - one thing we can all agree on - read more

Bahrain

Reversing Flash TimeLine using setInterval

There are many ways to reverse frames … i just did'nt find one that will satisfy my needs , so ended up with my creation :)

*Add the code at your last frame in the actions Layer .
stop();
var speed:Number = 20;
function goprev() {
if (_root._currentframe == 1 ) {
clearInterval(nIntervals);
trace("Stop");
}
prevFrame();
trace("going back");

}
var nIntervals = setInterval(goprev, speed);

  • Xplanation:

declared a Variable and called it speed limit its data type to Number , it will be used in the setInterval. will control the reverse speed.

var speed:Number = 20;

Next is the goprev() Function that will first check for the currentframe of the timeline if it fully reversed the timeline then it will clear the interval & stop the timeline , if not then it will keep on reversing the timeline untill it satisfy the condition .

function goprev() {
if (_root._currentframe == 1 ) {
clearInterval(nIntervals);
trace("Stop");
}
prevFrame();
trace("going back");
}

then our main controller , the setInterval

var nIntervals = setInterval(goprev, speed);

which is basicly used this way setInterval(name of the function, intervals as time in milliseconds);

Files can be found @ Zainals

Related posts:

  1. Pause flash TimeLine …
  2. ActionScript Idle Timer , Can be used as a screen Saver.

9 Responses to “Reversing Flash TimeLine using setInterval”

  1. On September 26, 2006 at 8:51 pm Alan Leffingwell responded with... #

    Greetings !!

    Ahh this flash example has helped me GREATLY !!! I had the need for a bunch of reversals embedded in a timeline and had been searching for ideas everywhere for a compact way how to do this WITHOUT using a moviceClip as a controller.. ty for this example i was able to apply it to my situation with slight modifications!

    kindest,
    Alan leffingwell

  2. On September 27, 2006 at 8:29 am Mohammed Zainal responded with... #

    Hey ,
    thanks for dropping in Alan .
    glad 2 know it helped someone , somewhere :D

  3. On February 2, 2007 at 5:34 am aum responded with... #

    hi , i have problem , your zip file i can’t unzip it state me unpect file format

    i use flash version 6

  4. On February 2, 2007 at 11:44 am Mohammed Zainal responded with... #

    hey aum ,
    sorry , but i dont have flash 5 anymore …

    but you can try it your self …
    open up a new flash file ,do a simple tween on the time line …

    on the last frame add the following code to the action layer:

    ======================================
    stop();
    var speed:Number = 20;
    function goprev() {
    if (_root._currentframe == 1 ) {
    clearInterval(nIntervals);
    trace(“Stop”);
    }
    prevFrame();
    trace(“going back”);

    }
    var nIntervals = setInterval(goprev, speed);
    ======================================

    hope that works since i never worked with any previous versions of flash but MX2004 …

  5. On February 4, 2007 at 10:13 pm Toasters responded with... #

    Hello,

    This has just helped me a lot! i had an animated MC button and needed it to reverse. Had originally animated it in but it meant that the button was sometimes left thinking that the mouse had rolled over it without it realising it had rolled out again.

    Just removed the _root. and applied the code directly to the button with an on (roll out) and it works a treat!

    Cheers

    Rob

  6. On February 4, 2007 at 11:01 pm Mohammed Zainal responded with... #

    hey toasters ,
    thanks for dropping by & im glad it worked …
    i’ll post a new code , soon hopefully for targeting multiple objects .

    so watch this space !

  7. On March 13, 2007 at 3:42 am Luke responded with... #

    wow.. i did what toaster did and it actually worked [which i am still shocked at]
    you RULE.

  8. On March 13, 2007 at 8:45 am Mohammed Zainal responded with... #

    nothing to be shocked about mate , practice makes perfect .
    Welcome & Thanks for the comment .

  9. On January 3, 2008 at 5:04 am Robi One responded with... #

    Works perfectly. Thanks!
    Q: hot to loop it? (it stops after reversing)

Add your response