I am using scene manager, and whenever I try to use a function in my main menu scene, it brings up an error when I release my mouse or finger.
Code:
11. local function button1touch(button, event)
12. if button:hitTestPoint (event.x, event.y)
13. print"change scene now"
14. end
15.end
stage:addEventListener(Event.MOUSE_UP, button1touch, button)
Error:
Scenes/main_menu.lua:12: attempt to index local 'event' (a nil value)
stack traceback:
Scenes/main_menu.lua:12: in function
Does anybody know why this is happening? Thanks!
Comments
However, if I may suggest: don't use Stage as an "event holder" unless you're sure of what you're doing. I did, and I went crazy hunting a memory leak since I wasn't removing some event listeners correctly.
My "workaround" (maybe not elegant, but seems to work until now ) is to create a global event Holder (that is visible everywhere since it's global) and nil it when I need to remove every event listener, so that every eventListener bound to it goes to garbage collection as I ask.
However, I think that one should try to keep as much things as possible local.
There are good chances that in this case you can add the event listener directly to the button.