How to reload Buttons in a specific scene?

Hi guys . I currently don’t know what to do my buttons dissapear whenever i go back to previous scene. For Example:

I proceed to scene1 using the start button in the Menu, then after a while i wanna go back to Menu. after going back to menu the Start Button dissapears along with the Options and Exit button.

How can i reload the buttons in a specific scene??

Are your buttons in the createScene function?  A little more information would help to determine what the problem is.  :wink:

Oh, I’m sorry.

Yes the buttons are all in the createScene function. All of them are already grouped. and my code in the exitScene function is;

function scene:exitScene(event)
    buttonGroup:removeSelf()
    buttonGroup = nil
    screenGroup:removeSelf()
    screenGroup = nil
end

the screenGroup properly reload but the buttons don’t.

OK I believe by using = nil you are completely destroying the object.  Removing that should let your buttons reappear.

The exitScene() is called when we are going to leave this scene, but still have visual elements on screen. This is a good place to remove event listeners, cancel timers and transitions, etc.

Have a look at this site which has a good storyboard example.

http://www.develephant.net/a-simple-storyboard-framework-for-corona-sdk-part-1/

I tried removing the “nil” but still the buttons don’t re-appear.

Can you post your complete createScene and exitScene code?

You should also consider moving to Composer as it is a much more up to date and stable scene manager.

removeSelf() removes a display object from the screen.

= nil will remove the reference to an object in memory.

Calling both of those, as you have, completely removes your button, first from the screen and then from memory.

You should only completely remove your buttons in the destroy event, otherwise you will need to recreate them when the scene comes back on screen. Try moving your removeSelf and nil code to the destroy function.

nevermind guys, i got it. Thanks for all the help. :wink:

Are your buttons in the createScene function?  A little more information would help to determine what the problem is.  :wink:

Oh, I’m sorry.

Yes the buttons are all in the createScene function. All of them are already grouped. and my code in the exitScene function is;

function scene:exitScene(event)
    buttonGroup:removeSelf()
    buttonGroup = nil
    screenGroup:removeSelf()
    screenGroup = nil
end

the screenGroup properly reload but the buttons don’t.

OK I believe by using = nil you are completely destroying the object.  Removing that should let your buttons reappear.

The exitScene() is called when we are going to leave this scene, but still have visual elements on screen. This is a good place to remove event listeners, cancel timers and transitions, etc.

Have a look at this site which has a good storyboard example.

http://www.develephant.net/a-simple-storyboard-framework-for-corona-sdk-part-1/

I tried removing the “nil” but still the buttons don’t re-appear.

Can you post your complete createScene and exitScene code?

You should also consider moving to Composer as it is a much more up to date and stable scene manager.

removeSelf() removes a display object from the screen.

= nil will remove the reference to an object in memory.

Calling both of those, as you have, completely removes your button, first from the screen and then from memory.

You should only completely remove your buttons in the destroy event, otherwise you will need to recreate them when the scene comes back on screen. Try moving your removeSelf and nil code to the destroy function.

nevermind guys, i got it. Thanks for all the help. :wink: