How to delete a button?

How can I delete/remove a button ;)?

I tried:
[lua]button:removeSelf()[/lua]
but this crashes the simulator [import]uid: 74852 topic_id: 12605 reply_id: 312605[/import]

By button, do you mean a button function or button as in a display object? Or both? [import]uid: 17138 topic_id: 12605 reply_id: 46171[/import]

@gyrospeter,
are you trying to run that from the button tap event?

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 12605 reply_id: 46180[/import]

I show a user interface with several buttons over the game scene.
When the user has finished the settings and presses the start-button I’d like to delete all buttons and start the game.

This is some of the code:

[lua]function InitButtons()

cmdStart = ui.newButton
{
default = “cmdStart.png”,
onEvent = startPhysics,
id = “cmdStart”
}

cmdStart.x = display.contentWidth/2
cmdStart.y = display.contentHeight - (cmdStart.height/2)

end

local startPhysics = function(event)
local physics = require(“physics”)
physics.start()
RemoveInterface()
end

function RemoveInterface()
if (cmdStart ~= nil) then
cmdStart:removeSelf()
end
end[/lua]

This code crashes the simulator [import]uid: 74852 topic_id: 12605 reply_id: 46189[/import]

This is a wild guess but give it a try:

In the code to create the cmdStart button, try changing onEvent to onRelease. Otherwise the startPhysics() is called twice, first on the button press and second on the button release. BUT! the second time around the button is not there to be removed.
[import]uid: 6787 topic_id: 12605 reply_id: 46345[/import]

Thanks for the hint, but the simulator crashes none the less.

Any other idea ;)? [import]uid: 74852 topic_id: 12605 reply_id: 46429[/import]

No one?

I believe there must be a possibility to remove a simple button ;)!
It’s a must-have. [import]uid: 74852 topic_id: 12605 reply_id: 46584[/import]

Try this, it works for me.
[lua]display.remove( cmdStart )
cmdStart = nil
[import]uid: 17138 topic_id: 12605 reply_id: 46643[/import]

The combination of

[lua]display.remove( cmdStart )
cmdStart = nil[/lua]

and

[lua]onRelease = startPhysics,[/lua]

seems to work. Thank you very much :)! [import]uid: 74852 topic_id: 12605 reply_id: 46653[/import]