Skip to main content
Participating Frequently
April 20, 2014
Answered

gotoAndPlay not working

  • April 20, 2014
  • 1 reply
  • 2673 views

Hey guys, I have a problem here. I have 2 buttons called start and settings and both buttons with change the next scenes after the movie ends.

Here's the sample of the code

Start button:

on (release)

{

  var o:Number = 1;

  gotoAndPlay (40);

}

Settings button:

on (release)

{

  var o:Number = 2;

  gotoAndPlay (40);

}

In the real animation, after I click on 1 of the buttons, the animation will slowly go white and at the final, it does this code:

trace(o);

if (o == 1)

          {

                    gotoAndPlay ("Selections");

          }

          else if (o == 2)

          {

                    gotoAndPlay ("Settings");

          }

But, the 'gotoAndPlay' doesn't work. I have applied this code on another scene and doesn't work too. Is there something wrong with my code?

This topic has been closed for replies.
Correct answer kglad

you're making 'o' local to your button-scope when you prefix with var within those on(release) methods.  also, no code should be attached to objects.  attach code to timelines.

ie, name your buttons (eg, btn1 and btn2), remove the code you have now attached to those buttons and use:

var o:Number;

btn1.onRelease=function(){

o=1;

gotoAndPlay(40);

}

btn2.onRelease=function(){

o=2;

gotoAndPlay(40);

}

1 reply

kglad
kgladCorrect answer
Community Expert
April 20, 2014

you're making 'o' local to your button-scope when you prefix with var within those on(release) methods.  also, no code should be attached to objects.  attach code to timelines.

ie, name your buttons (eg, btn1 and btn2), remove the code you have now attached to those buttons and use:

var o:Number;

btn1.onRelease=function(){

o=1;

gotoAndPlay(40);

}

btn2.onRelease=function(){

o=2;

gotoAndPlay(40);

}

SonicSkyAuthor
Participating Frequently
April 23, 2014

Thanks kglad, but I've tried your method and the code still won't work correctly. I thought that the wrong part was at the if clause because the buttons do their job perfectly.

kglad
Community Expert
April 27, 2014

I've got the solution!! The gotoAndPlay won't go to the targeted scene, but will go to a labeled frame in the scene. So, label the frame in the targeted scene and change the name of the scene in the "gotoAndPlay()" to the name of the labeled frame.


correct.  never use scenes in as2 navigations.

also, you should use the goto methods, not functions:

_root.gotoAndPlay("Settings");