How to switch frames in this case?

3 posts

Flag Post

Hi everyone!

I’m trying to make a new game, now I’m trying to separate the menus in different frames, but it isn’t working like I wished…

The frames are separated like this:
– frame1: Start Menu
– frame2: New Game Menu
– frame3: Load Game Menu

In the first frame, I have a button to go to the second and another to go to the third. And in the second and third, I have a button to go back to the first.

I made this code:

function onLoad(){
     _root.newGameB.onPress = function(){
     _root.loadGameB.onPress = function(){
     _root.backMenuB.onPress = function(){

the buttons: newGameB and loadGameB are in the 1st frame; and the button: backMenuB is in the 2nd and in the 3rd.

What is happening is that I’m able to go to the 2nd or 3rd frames by the 1st, but I’m unable to go back by the backMenuB button.

What should I do to make it work?


Flag Post

Best solution:

Make each button a class that has its own on load.

Alternate solution:

Don’t add the events until the button exists (i.e. you change frames)

Note: if you add your event listener for your first button, then change frames, when you come back, that button will not have event listeners anymore.

Flag Post

You’re the man!

Thank you again!