removeEventListener

Hi.

Is there any way to know if there il a event listener (or many) applied to an object ?
Can I Remove all the event listener of an object ?

thank’s

At the moment, it seems that when you attach an event listener to an object it will have a table called “_functionListeners”. If you iterate through you can see what type of listener it has attached.

As for the second question, this function should do the trick.

local function hasListener(obj, removeAll)
	if not obj._functionListeners then return false end
	for eventType,v in pairs(obj._functionListeners)do
		print("Has a " .. eventType .. " listener.")
		if removeAll then
			for _,func in pairs(v) do
				print("Removing event listener.")
				obj:removeEventListener(eventType,func)
			end
		end
	end
end

Ah Yes :muscle:

That’s works perfectly !
Thank you Juni !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.