Skip to main content
April 16, 2011
Answered

Problem with go to and play

  • April 16, 2011
  • 1 reply
  • 1194 views

Hi I'm making a simple web with 4 buttons. And i made the respective links, with gotoAndPlay in as3. Everything is working good, but when i click on the last button, the btn 4, and then want to go to the btn 3 it doesn`t work. It only work, when i want to go from button 4 to 2, and 4 to 1. Why is happening this? Here is the code:

stop();
btn1.addEventListener(MouseEvent.CLICK,funcion1);

function funcion1(evt:MouseEvent):void{
    gotoAndPlay(10);
};

btn2.addEventListener(MouseEvent.CLICK,funcion2);

function funcion2(evt:MouseEvent):void{
    gotoAndPlay(20);
};

btn3.addEventListener(MouseEvent.CLICK,funcion3);

function funcion3(evt:MouseEvent):void{
    gotoAndPlay(30);
};

btn4.addEventListener(MouseEvent.CLICK,funcion4);

function funcion4(evt:MouseEvent):void{
    gotoAndPlay(40);
};

PD: I'm sure all the buttons have the instance name in all frames (10;20;30;40)

This topic has been closed for replies.
Correct answer randy_troppmann

Which frame are you adding the button event listeners? I am assuming frame 1. Every time you put a keyframe on the timeline you are essentially re-instantiating the movieclip on that layer and you can't expect that an event listener you added previously will still apply after the new keyframe. There are a bunch of different ways to solve this. In your case the easiest way would be to, on each keyframe, remove the button event listeners (in case they are there, avoiding memory leaks) and then add them again. Not the best appoach, but it should work.

HTH.

- Randy

1 reply

Ned Murphy
Legend
April 16, 2011

How are your buttons arranged along the timeline?

April 16, 2011

IS LIKE THIS. THE 4 COLOR IMAGES ARE THE BUTTONS.THE BIGGER PIC IS THE INDEX.

Ned Murphy
Legend
April 16, 2011

For the problem you say you are having, btn3 in the last keyframe would be the most suspect.  You need to check every keyframe for btn3 and make sure you have the instance name assigned.

Another thing you should do is not use gotoAndPlay if the intention is to gotoAndStop at those keyframes.  What will happen is if you click the same button twice using gotoAndPlay, it will play on to the next frame that tells it to stop.  Using gotoAndStop will solve that.