Event listeners?

Hi,
How can I assign a eventListener to a variable?

Do I just do

myListener = obj:addEventListener("event", listener)

?

EDIT:

Hey, sorry, wasn’t very descriptive.

I’m listening for a touch, so

myVariable = obj:addEventListener("touch", myListener)

I want to assign the eventListener to a variable because I want to

myVariable = obj:removeEventListener("touch", myListener)

remove the event listener - I was trying to remove an event listener to the object but it said I supplied a “nil key for property lookup”. So,if I assigned it to a variable, would the simulator know what I was talking about? I had 4 event listeners on the “obj”, so I don’t think the simulator knew which one - and it was in a different function, was that part of it?

Thanks as always,

cozymonster

What “event” are you listening for exactly?

The “touch” event (it seems to be more sensitive on a Corona simulator than “tap”. Is that true?).

First you don’t need to save a reference to the event listener to remove it.

If you do:

obj:addEventListener(“touch”, someFunction)

just do:

obj:removeEventListener(“touch”, someFunction)

to remove it.  Simply copy the Add code, paste it where you want to remove it, change “add” to “remove”.  You cannot use anonymous function (lua closures) to make this work because remove has to have the same pointer to the function created in addEventListener in remove it.

If you are removing the object, it will remove the eventListener with it, so you really only have to remove it, if want the object to stay on the screen but no long respond to events (like disabling a button).

Touch seems more responsive because a “Tap” has to have a touch began and touch ended that iasts a few miliseconds to be counted as a tap.  I almost always use “touch” and just react on the “ended” event.phase and take the tap’s duration out of it.

What “event” are you listening for exactly?

The “touch” event (it seems to be more sensitive on a Corona simulator than “tap”. Is that true?).

First you don’t need to save a reference to the event listener to remove it.

If you do:

obj:addEventListener(“touch”, someFunction)

just do:

obj:removeEventListener(“touch”, someFunction)

to remove it.  Simply copy the Add code, paste it where you want to remove it, change “add” to “remove”.  You cannot use anonymous function (lua closures) to make this work because remove has to have the same pointer to the function created in addEventListener in remove it.

If you are removing the object, it will remove the eventListener with it, so you really only have to remove it, if want the object to stay on the screen but no long respond to events (like disabling a button).

Touch seems more responsive because a “Tap” has to have a touch began and touch ended that iasts a few miliseconds to be counted as a tap.  I almost always use “touch” and just react on the “ended” event.phase and take the tap’s duration out of it.