Actionscript: Play up to a certain point

I have a timeline with 100 frames. It is basically one long animation. I have keyframes on frames 1, 25, 50, and 75.

I have 4 different buttons. If the user clicks one, it will go to a specific keyframe. For example, if somebody is on the frame 50 keyframe, and they click on the button that sends them to the keyframe on frame 25, instead of just jumping to frame 25, the animations plays from 50 all they way to the end of the timeline, starts over and stops at 25. ( The animation is a spinning wheel if that helps visualize)

They could click on any button, from wherever they are, and the animation will play to the specific keyframe.

So, basically a script that says, "play until the playhead reaches a certain frame (or label) then stop. I obviously cannot use a simple ‘play’, and have a ‘stop’ at the frame I want, because where the animation needs to stop will always be different.

Thanks

So, on each of the 4 buttons, my script should look like this?:

on (release) {
	frameToStopAt = 25;
	circleMC.play();
}

And then, within circleMC, I have my 100 keyframe tween. I have another layer above this only for actionscript. On frames where I want the animation to stop, I type the following:

if (frameToStopAt == 25) {
   stop();
}

(Changing the numbers for each button & keyframe of course)
Does that look correct?

My buttons seem to be ignoring the stop points…

I’m going to assume you have the code to make a button click work.

On each click, you want to set a variable.

So on the click of each button, set the frame number you want to stop at. Something like this:

frameToStopAt = 25;

or

frameToStopAt = 75;

Then on the keyframes, put this:

if (frameToStopAt == 25) {
   stop();
}

Changing the number for each keyframe of course.

Good luck! :slight_smile:

Yes, that’s pretty much right.

But to reference our frameToStopAt variable from inside the circleMC you’ll need to use:

if (_root.frameToStopAt == 25) {
   stop();
}

or

if (this._parent.frameToStopAt == 25) {
   stop();
}

ActionScript needs to know the variable you want to check is on the main timeline.

Let me know how you get on, as we may need to declare the variable on the maintime and then change the way it gets set on button click, but that’s not too hard.

Yes, I was neglecting to reference the proper path. I knew that applied to symbols, and now I know it applies to variables as well. Thanks for your help, it appears to be working now. Great solution.:slight_smile:

Glad to help, and glad it works. :slight_smile:

An alternate method would be to just have the click function of the button be:


play();

then on the keyframe where it needs to stop, just put:


stop();

A little less low-tech, but it’d do the trick.

There is also a more sophisticated method you could use involving an Event.ENTER_FRAME event listener.

Actually, that wouldn’t work for what I’m trying to do because I need it to bypass certain frames, based on which button the user clicks on. If the user clicks a button that says, “go to frame 75”, and the playhead is on frame 1, I need the movie to play keyframes 1-74, then stop on 75. Because I have other stop points on frames 25 & 50, simply writing stop(); on the keyframes would not work.

The page should be live this week, maybe I’ll post a link to help describe it better. Thanks for everyone’s input.