question about widget

Hi

I have a question about objects of widget. I’m working with storyboard scenes and in one scene called “menu” I have create a button “play” with the following code:

local StartButton = widget.newButton{
id = “btn001”,
style = “blue2Large”,
fontSize = 18,
left = 500,
top = 380,
label = “Play”,
width = 150, height = 46,
cornerRadius = 8,
onEvent = StartButtonEvent
}

This is working fine, and when I touch the button the defined onEvent (StartButtonEvent) will execute. Inside the local function StartButtonEvent, I remove the button with the following lines

display.remove(StartButton)
StartButton = nil

After this I switch to another screen. Problem is, in the new scene the button is not visible (thats ok) but the onEvent is still active, this means if I tape in the region where the StartButton was placed the StartButtonEvent will execute again.

Questions:
If I remote the widget object, then only the object and not the event listener to this object will remove ? Is this a buck or is this normally ?

Who can I remove the event listener of my widget object, or how can I get the name and the necessary parameter of this event listener to use the removeEventlistener function?

Thanks for help
Greetings
Michael [import]uid: 96270 topic_id: 25764 reply_id: 325764[/import]

Tip #1: encapsulate your code with < code > < / code > (without the spaces, so that us programmer types are eager to read it

  1. Which build are you using?

  2. Remember that widget.newButton doesn’t use event.phase in the same way as normal event functions. I would check the docs to see what it uses.

I just tried something very similar to your sample, and I can remove the object with no problem so long as I don’t check for event.phase == “ended”.

  1. Make sure you delete the button before using gotoScene() – I couldn’t get your problem either way, but it might be as simple as that.

  2. If you need a workaround, you can probably use (?)

[lua]StartButton:removeEventListener(“touch”, StartButtonEvent)[/lua] [import]uid: 41884 topic_id: 25764 reply_id: 104222[/import]

(dupe, removed) [import]uid: 41884 topic_id: 25764 reply_id: 104259[/import]