Reversing Flash TimeLine using setInterval

14 06 2006

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

Advertisements

Actions

Information

14 responses

26 09 2006
Alan Leffingwell

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

27 09 2006
Mohammed Zainal

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

2 02 2007
aum

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

i use flash version 6

2 02 2007
Mohammed Zainal

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 …

4 02 2007
Toasters

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

4 02 2007
Mohammed Zainal

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 !

13 03 2007
Luke

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

13 03 2007
Mohammed Zainal

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

23 03 2007
Joel

Hi, the script works well, I’m trying to get something similar to work where based on an external variable the movie plays backwards or forwards. I’ve tried putting the same script at the beginning so that it would ping-pong between frames, reversing from frame 35 to 1 and then back but I can’t work out what is stopping the script from playing?

Suggestions for a newbie? (except RTFM!)

Regards,

joel

22 08 2007
Chris

Hey, that is really helpful been looking for the answer to rewinding the timeline without the use of btns, i had been working on getting some code but to no luck, keep up the good work.

Regards

Chris
(Creative Design Student)

19 03 2009
Glenn

Wow! I pasted it in and it just worked! How often does that happen!

I’m not very proficient in Flash so finding this was a real gem.

Thanks!!

4 02 2010
Arun Satyal

Nice Idea… keep it up..

9 06 2010
Andrew hague

I’ve got your script working but I need it to reverse the timeline to a specific frame rather than frame 1.

any ideas how i would adapt the script to do this?

24 12 2013
Web Site

The laser is specialized to target the pigment of the skin to effectively remove the tattoo.
It will not be long and therefore the boomers will require care and have the identical goals:
aging in place. We work at our offices each day and don’t take much time
to think about how things might be different.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: