I just noticed after double checking my main.lua. All of the function that link my storyboard doesn’t have a event listener attached to each of them. Does that will work ? Because I create this, using references from Corona samples project. One of the sample project is using a storyboard API without adding event listener to the main.lua
Everything seemed to work for me … you do not need the addListener calls in main.lua, they go in the storyboard scene file (like you have).
have you tried the code? It didn’t run with the simulator. which is confusing.
I have found the problem. It persists on the onEvent, on the button options. I simply change it to onPress, and it worked like magic
Just for those who want to know why this fix worked:
widget.newButton’s onEvent is a “touch” handler. It gets called twice: once on press and once on release. These come in known as phases: “began” and “ended”. So any time you use onEvent, the function is going to fire twice. You have to look for the phase and trap for it. onPress and onRelease events only call once so you don’t need an if statement.
Rob
thanks for the advanced tip, Rob! btw, when does onEvent usually used? Does it mean that you can’t use it to buttons?
onEvent allows you to react to the state of the button. Lets say you wanted to have a feature where while holding the button down a power bar increases. You could set a flag in the onEvent’s “began” phase, then using an Runtime “enterFrame” listener, increment the power bar while the flag is true and then when you let up, onEvent fires again clearing the flag.
Rob
so it would create more possibilities to trigger different function, while being pressed, released, and the moment the button is pressed? Thanks for the in depth explanation. will do remember that when it would come to some cases!
I believe you can use onEvent with one function to handle both up and down, or you can use onPress and onRelease as separate functions. I don’t’ think you can use onEvent with onPress/onRelease