Play it Again, Sam: FLASH Timelines in Reverse

Sooner or later, every Flash developer is surprised to learn how difficult it is to play a movie backwards in FLASH. When this happens, instinct sends them to one of more than 20 different methods described in online tutorials.

Most methods for playing a Flash movie backwards require the programmer to embed a movieclip containing actionscript that monitors the _root level move and determines when it needs to play backwards and where to stop.

This brief tutorial presents an alternative approach that can be implemented and scaled to virtually any Flash project. The tutorial is brief because only a few lines of code are required. In fact, It's as easy as 1-2-3.

1. Call to Action

Create an actionscript layer that extends the full length of your movie. In that layer, include the following actionscript:

function Movement() {
  if (_root._currentframe > _root.mytarget){
    prevFrame();
  }else if (_root._currentframe < _root.mytarget){
    nextFrame();
  }else{
    stop();
  }
}
this.onEnterFrame= Movement;

2. onPress your buttons

Attach code to your buttons that tells the script the frame to stop on when clicked:

on(Press){
  _root.mytarget=59;
}

Using the code above, the movie will play either backwards or forwards to the desired destination.

3. Avoid all Stops

As written, the code eliminates the need to have stop() commands throughout the movie since you can indicate all stopping points within navigation. Movieclips can still be used on stopped frames to create animations as desired.

Over time, you'll find this method of moving backwards and forwards in the timeline to be very adaptable. Enjoy!

Comments

Sorry, thats a bit CPU intensive for me

Flash is a cpu hog already, don't encourage it! this.onEnterFrame= Movement; will be called repeatedly when we only want it to run when animation is required. Also your function only deals with _root animations so I have re-written it to work for a targeted object, the function now has a ' targ_mc' parameter where you can specify the clip you want to animate ( for this example it remains _root).

function movement(destination, targ_mc) { targ_mc.onEnterFrame = function() { if (targ_mc._currentframe>destination) { targ_mc.prevFrame(); } else if (targ_mc._currentframe

In the button(s) we now put this code to target the _root animation

on (release) {
movement(45,_root);	
}

Obviously that button will take _root to frame 45. But If we wanted a clip called "car" on the root to play to frame 10, we would use :

movement(45,_root.car);

damn, that mangled my code block

here's that function again, I dont seem to have grasped Evolts code commenting. Ifully expect this one to look terrible also
function movement(destination, targ_mc) {
	targ_mc.onEnterFrame = function() {
		if (targ_mc._currentframe>destination) {
			targ_mc.prevFrame();
		} else if (targ_mc._currentframe