Reversing frames on button release

hello,
i am making an animation which plays out about 30 frames. on frame 30 i have an invisible button, and when released i want it to play all the frames back until it reaches frame 15, at which point it stops. I have the following code but it does not work the way i’m hoping:

on (release) {
 if (_currentframe == 15) {
  stop();
 }
 else if (_currentframe != 15) {
  prevFrame();
 }
} 

if anyone can help me out i would greatly appreciate it. thanks in advance.

A quick copy&past from some code I posted on another forum. So just ignore the Dutch comments :stuck_out_tongue: Should help you a bit. Demo here: http://www.henxcom.com/mediamonkey/flashfiles/playfuncties.html

[AS]// dit moet je zelf goed invullen!!!
var fps = 30;

// vervangt de standaard play() van een movieclip
function playForward(mc) {
clean(mc);
mc.play();
}

// functie om terug af te spelen.
function playBackward(mc, halt) {
mc.onEnterFrame = function() {
if (this._currentframe == 1) {
(halt) ? delete this.onEnterFrame : this.gotoAndStop(this._totalframes);
}
clearInterval(_root.ff);
clearInterval(_root.fb);
this.prevFrame();
}
}

// “stopt” (pauzeert) de mc/swf
function pauze(mc) {
clean(mc);
mc.stop();
}

// stopt de mc echt, en gaat terug naar het 1e frame
function stoppen(mc) {
clean(mc);
mc.gotoAndStop(1);
}

// deze functie speelt de mc versneld af
// gebruik ‘speed’ als factor: bv 2 voor 2x zo snel, of 0.5 voor de helft zo snel
// gebruik ‘halt’ als boolean om de animatie wel of niet te loopen
function fastForward(mc, speed, halt) {
clean(mc);
var time = 1000/fps/speed;
ff = setInterval( function() {
mc.nextFrame();
if (mc._currentframe == mc._totalframes) {
(halt) ? clearInterval(ff) : mc.gotoAndStop(1);
}
}, time);
}

// deze functie speelt de mc versneld terug af
// gebruik ‘speed’ als factor: bv 2 voor 2x zo snel, of 0.5 voor de helft zo snel
// gebruik ‘halt’ als boolean om de animatie wel of niet te loopen
function fastBackward(mc, speed, halt) {
clean(mc);
var time = 1000/fps/speed;
fb = setInterval( function() {
mc.prevFrame();
if (mc._currentframe == 1) {
(halt) ? clearInterval(fb) : mc.gotoAndStop(mc._totalframes);
}
}, time);
}

// verwijdert alle intervallen en de onEnterFrame, als die wordt gebruikt
function clean(mc) {
if (mc.onEnterFrame) mc.onEnterFrame = null;
if (ff) clearInterval(ff);
if (fb) clearInterval(fb);
}

// Als je die interval geen mooie oplossing vind kun je ook een
// functie bedenken die berekent op welke frame de mc/swf moet staan
// en er direct naar verwijst.[/AS]

hey mediamonkey, i think your code is a little too complicated for this problem, and the dutch comments just make it worse. I was trying to get some code working for this but couldnt :confused:

Ok, I got it:


onClipEvent(enterFrame){
	if( _root._currentframe == 30 ){
		_root.enter30 = true;
	}
	if( _root.enter30 == false && _root._currentframe < 30 ){
			_root.nextFrame();
	} else if ( _root.enter30 == true && _root._currentframe > 15 ){
		_root.prevFrame();
	}
	if( _currentframe == 15 && enter30 == true ){
		stop();
	}
}

Attach this code to something in your animation. And add the line:

enter30=false;

attached to frame 1.

You can look at the attached file also.

Thanks a lot, but I tried your code and it didn’t work for me (and your code was wayyyyyy to confusing with the dutch comments, lol, thanks though). I’ll link to an FLA since the limit on this board is 75k and this one is 112k.

On frame 45 there is an invis button (on top of the work text, instance name workBack) that on release needs to play the frames back until it reaches frame 15 at which point it stops. This is all in the work movieclip (on the bottom under the bottom bar). Many thanks to anyone who can help me as i’ve tried numerous amounts of code with nothing resulting the way i want it to work.
http://www.reintroducing.com/index.fla

Did you look at mine? I know it works, and is fairly simple I thought.

Place this code on the end of the timeline, along with the stop() :


workBack.onRelease = function() {
	this._parent.onEnterFrame = function() {
		this.prevFrame();
		if (this._currentframe == 15) {
			delete this.onEnterFrame;
		}
	};
};

you’re the man voetsjoeba, thanks a ton!

Anytime :slight_smile:

Alright, i have a bit of a newer problem that involves still the same concept. I duplicated the movie clip so i have two menu’s now, and i have an invisible button on frame 15 that i want to collapse the other menu when this one is clicked. so it’ll be like a see-saw motion where when one is clicked the other reverses its frames, and vice versa. How would i go about doing that? I have tried a lot of things and modifying voet’s code and it wasn’t working right for me… :\ Any help is greatly appreciated.

I’d say something like this:


menu1.onRelease = function() {
	this.play();
	menu2.onEnterFrame = function() {
		this.prevFrame();
		if (this._currentframe == 15) {
			delete this.onEnterFrame;
		}
	};
};
menu2.onRelease = function() {
	this.play();
	menu1.onEnterFrame = function() {
		this.prevFrame();
		if (this._currentframe == 15) {
			delete this.onEnterFrame;
		}
	};
};

Not sure if i put it in correctly but i put that code on frame 15 of the index movie clip (the clip for the index menu) as follows:

indexStart.onRelease = function() {
 this.play();
 workStart.onEnterFrame = function() {
  this.prevFrame();
  if (this._currentframe == 15) {
   delete this.onEnterFrame;
  }
 };
};

Then i went ahead and put this code on frame 15 of the work movie clip (the mc for the work menu):

workStart.onRelease = function() {
 this.play();
 indexStart.onEnterFrame = function() {
  this.prevFrame();
  if (this._currentframe == 15) {
   delete this.onEnterFrame;
  }
 };
};

but that didn’t seem to work. Am i putting the code in the wrong place?

I also tried to put _root.work.workStart for the path in the first code to see if it would control that button then but it didn’t work either.

oops, nevermind, i’m an idiot and i got my instance names messed up.

once again voetsjoeba, you are the man! i really appreciate all the help you have offered me.

ahh ****it, i’m sorry again. new problem i didn’t recognize before. so i have the two movie clips at frame 15 when the movie starts (there is a little intro animation of them moving up when it loads the clips, hence why it stops 15 frames down the line waiting for them to be pressed). if i press one of them while none of them are past frame 15, it reverses the frames to frame 1 for the one that wasn’t pressed so it collapses all together under the movie where it is not visible anymore.

aaaaaaaaaand i fixed my own mistake again, lol. if you’re interested, it was this:

workStart.onRelease = function() {
	this.play();
	_root.index.onEnterFrame = function() {
		if (this._currentframe == 15) {
			delete this.onEnterFrame;
		} else {
		this.prevFrame();
		}
	};
};

again, thanks so much for your help.

Hehe, no problem :slight_smile: