Log in

View Full Version : Playing flash backwards to a stop



nate51
02-20-2009, 04:03 PM
I have seen a lot of different ways on the net to play tweens backwards, most common is the prevFrame(); command I find.

The only trouble is I have a tween that has keyframes that stop. So I need to find out how to have a prev button that plays the tween inside an mc backwards to either a stop command or a designated frame number set in the button itself.

Does anyone know of any tutorials or can give me some insight as to how to go about it?


-- Nate

punstc
02-20-2009, 06:01 PM
One way to do it is to make a direction variable and say currentframe + what ever the direction so going forward would be dir = 1 going backward dir = -1

So it is constantly checking to see if it should go forward or backwards you could us an EnterFrame event and then with other event listeners change the direction.

heres an example put together on some buttons since its pretty self explanitory

the files at.

www.jchamb.com/files/buttons.zip

each button is an instance and the code is inside of that button, but could easily be worked around in other ways.

nate51
02-20-2009, 07:01 PM
Hey punstc,

Great example and it works really well, but do you know if the idea would work where the animation is in a seperate mc from the button and the mc had stop commands?

I am wondering because the way it works I wonder if it would bypass the stop(); frame like the prevFrame(); command does.

punstc
02-20-2009, 11:08 PM
Off the top of my head I would say yes since its running off of an enter frame and just goes to the next or previous frame its not really paying attention to stops and other things on the timeline.

I'll see if I can throw together another example for you here in a bit when i get a chance.

UPDATE

alright i got it working. There is one problem with the current way i have it set up though. If you try to add in multiple movie clips using the same functions and var (in the examples case dir) since they are all waiting to hear from that dir they will all go. If you would take the time and write conditional statements out and creat a couple other variables you should be able to apply it to more then one movie clip at a time.

heres the example file:
www.jchamb.com/files/buttons2.zip

nate51
02-21-2009, 01:11 AM
No need, I solved my own problem. Here how I went about it for anyone who is looking for the same solution.

On my main timeline I have my two arrows (left and right) and my thumbnails slides. I made a tween to scroll through the thumbnails in groups of three. The first frame has this AS

rewind_btn.onPress = function() {
onEnterFrame = function(){
prevFrame();
}
}
forward_btn.onPress = function() {
onEnterFrame = function(){
nextFrame();
}
}
stop();
onEnterFrame = function() {
delete onEnterFrame;
}

which sets up the buttons actions and a stop command.

I placed this code on the rest of the stop frames

stop();
onEnterFrame = function() {
delete onEnterFrame;
}

The "stop();" alone will be ignored when the tween is played in reverse so thats what the "delete onEnterFrame" command does.

And that's it, it works like a charm. Hopefully this post will help anyone else with this problem.

felipedavolta
02-24-2010, 12:43 AM
I have just used nate51's solution to create a sliding menu with stops forward and backwards. Worked ok. But what if I want to make it loop?? I mean.. when I'm on the last frame, I've put a gotoAndPlay(1) and I'm set.
But what about the first frame?

thank you