How to Use Two gotoAndPlay Actions with One Button Press?

  • Novice
  • Novice
  • Posts: 17

Post 3+ Months Ago


Does anyone know how to use two gotoAndPlay actions when a button is pressed?

E.g. when the user presses a button I want it to play the roll-over animation (Frames 1 - 51) THEN play the down animation (Frames 52-70)! Heres what Ive got so far, though at the moment it just skips straight to the "_down" part!

Code: [ Select ]

btnHit3DModelling_mc.onRelease= function(){
  1. btnHit3DModelling_mc.onRelease= function(){
  2.         btn3DModelling_mc.gotoAndPlay("_over");
  3.         btn3DModelling_mc.gotoAndPlay("_down");
  4.         }
  5.     btnHit3DModelling_mc.enabled=false;
  6. }

Simply repeating the over animation in the down section is not really possible due to large file size.

Many Thanks, Ben. :)
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

Hey Ben whats happening here is that flash runs code in order so its going to the "_over" label and then going to the "_down" state instantly after that. IE its trying to do the "over" but your command tells it to do the "down" before the you actually have time to see the effect of the first command.

So you can do what you need with a variable and a few if statements

Code: [ Select ]
btnHit3DModelling_mc.onRelease= function(){
  if(this.s == "start" || this.s == undefined){
   this.s = "over";

  if(this.s == "over"){
   this.s = "start";

  1. btnHit3DModelling_mc.onRelease= function(){
  2.   if(this.s == "start" || this.s == undefined){
  3.    btn3DModelling_mc.gotoAndPlay("_over");
  4.    this.s = "over";
  5.   }
  6.   if(this.s == "over"){
  7.    btn3DModelling_mc.gotoAndPlay("_down");
  8.    this.s = "start";
  9.   }
  10. }

So whats going on here is the first statement checks to see if the variable "s" is equal to start or if its undefined (this is the very first state when the button has never been pressed because we didn't set "s" to be anything)

If the "s" is equal one then flash plays the "over" animation and sets the variable "s" to equal over

Then if the button is pressed again the first statement won't fire because "s" is not equal to either start or undefined. However, it will play the second statement because "s" is now equal "over"

At the end of the over statement we reset "s" to equal "start" so the first part runs again on the 3rd btn press

Now there's a catch here. If you press the button twice quickly the animation will go to the second state right away since the system isn't checking to see if the action has finished. You can solve this a few different ways. You can write script to set "s" only after the timeline has gotten to a specific point or you can test if "s" is equal to over AND the current frame of the animation is equal to the last frame of the "over" section.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2016. Ozzu® is a registered trademark of Unmelted, LLC.