Hello,
I have this code:
function button:onTouchesEnd(event)
print(type(event))
if button:hitTestPoint(event.touch.x, event.touch.y) then
Event:dispatchEvent(Event.new("hello"))
print("hello")
end
end
button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd) |
and am getting this error:
main.lua is uploading.
Uploading finished.
nil
main.lua:27: attempt to index local 'event' (a nil value)
stack traceback:
main.lua:27: in function <main.lua:25> |
I compared my code to working code of mine and can't figure out what's wrong with this...
I hope s.o. can tell me what I'm doing wrong.
Thanks
David
Comments
button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, self)
in the last line?
also
self:hitTestPoint(event.touch.x, event.touch.y)
Likes: dddent
Fragmenter - animated loop machine and IKONOMIKON - the memory game
button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, button)
or
self:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, self)
inside a button:... function
Likes: dddent
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Passing button instead of self makes sense, but shouldn't the event alsways pass the table with the touch coordinates, and the error shoud have been that self had a nil value? I understand why I have to pass button, but I don't understand why that solved the error...
Likes: ar2rsawseen, dddent