Copy link to clipboard
Copied
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?
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
copy and paste your corrected code.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
correct. never use scenes in as2 navigations.
also, you should use the goto methods, not functions:
_root.gotoAndPlay("Settings");
Find more inspiration, events, and resources on the new Adobe Community
Explore Now