Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

gotoAndPlay not working

New Here ,
Apr 20, 2014 Apr 20, 2014

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?

TOPICS
ActionScript
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 20, 2014 Apr 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);

}

Translate
Community Expert ,
Apr 20, 2014 Apr 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2014 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2014 Apr 23, 2014

copy and paste your corrected code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2014 Apr 24, 2014

kglad wrote:

copy and paste your corrected code.

var o:Number;

startbtn.onRelease=function()

{

     o=1;

     gotoAndPlay(40);

}

settingsbtn.onRelease=function()

{

     o=2;

     gotoAndPlay(40);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2014 Apr 24, 2014

on frame 40, what's your trace show (after clicking one of those buttons)?

and what frame is your timeline on when you click your buttons?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 25, 2014 Apr 25, 2014

kglad wrote:

on frame 40, what's your trace show (after clicking one of those buttons)?

and what frame is your timeline on when you click your buttons?

Both buttons traces the correct number and the buttons is on frame 1.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2014 Apr 26, 2014

if your frame 40 trace shows what you expect, and your timeline is failing to goto the correct frame labels, those labeks do not exist in the frame 40 scene.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2014 Apr 26, 2014

The buttons goes to the correct frame, but at last doesn't go to the correct scene. It always goes to the next scene, not the targeted scene. I think the problem is in the final code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2014 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2014 Apr 27, 2014
LATEST

correct.  never use scenes in as2 navigations.

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

_root.gotoAndPlay("Settings");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines