How to check an object has an eventListener

Can’t seem to find Corona api that checks whether an object has an event listener. Is there one? If not, how to check an image has an event listener?

We add an event listener to a table called image typically like this:

image.button:addEventListener( “tap”, onTap )

After registering the listener, you could simply store the information that the image has an event listener:

image.button.hasTapListener = true

Thanks Memo - that sounds good. Only, there will be a number of objects receiving the event. Yes we can remove one at a time, but how to iterate through the image table to find .hasTapListener?

Started with:

for k,v in pairs(image) do if k.hasEventListener then print(k,v) end end

But in pairs isn’t working. How to evaluate the state of .hasTapListener as I guess it isn’t a key?

Try “if( v.hasEventListener)” instead

Also check that you actually called it the same thing in both places, you’re writing hasEventListener in the code and hasTapListener in the post :slight_smile:

There is no such API:

You can check the utility provided on this site:

http://www.ludicroussoftware.com/blog/2011/12/23/haseventlistener-in-corona/

Thanks Memo - that did the trick.

Interesting utility there primoz.cerar could be useful.

After registering the listener, you could simply store the information that the image has an event listener:

image.button.hasTapListener = true

Thanks Memo - that sounds good. Only, there will be a number of objects receiving the event. Yes we can remove one at a time, but how to iterate through the image table to find .hasTapListener?

Started with:

for k,v in pairs(image) do if k.hasEventListener then print(k,v) end end

But in pairs isn’t working. How to evaluate the state of .hasTapListener as I guess it isn’t a key?

Try “if( v.hasEventListener)” instead

Also check that you actually called it the same thing in both places, you’re writing hasEventListener in the code and hasTapListener in the post :slight_smile:

There is no such API:

You can check the utility provided on this site:

http://www.ludicroussoftware.com/blog/2011/12/23/haseventlistener-in-corona/

Thanks Memo - that did the trick.

Interesting utility there primoz.cerar could be useful.