Object Listener Removals

I wanted to find out if calling object:removeSelf() will also remove event listeners of the object and the object’s children?

If not, when I dynamically generate an object and give it a listener, I track it in a table allObjects and delete the object later. Is there an elegant way to get at the listener to remove it before deleting the object? [import]uid: 75335 topic_id: 12755 reply_id: 312755[/import]

Unfortunately No!!

removing an object does not remove the handler/event listener. The other thing is that even eventListeners are a bit picky, in the sense you have to have the same signature of the function to remove it as to add it.

@CoronaSDK it would be easier if there was a handle to the listener and that could be used to remove the event listener, it would make development a lot more easier than the method of signatures.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 12755 reply_id: 46769[/import]

So, I’m doing something in a loop

loop {
local var = newImageRect(…)
localGroup:insert(var)
table.insert(objectArray, var)
var:addEventListener(“touch”, myTouchHandler)
}

How, when I’m inside my clean function do I get at the event listener for that variable?

If I have something like…

while #objectArray>=1 do
local temp = table.remove(objectArray, #objectArray)
temp:removeEventListener(“touch”, myTouchHandler)
temp:removeSelf()
end

Will that properly kill all attached event listeners on the object? Then however the problem becomes that I place multiple objects with different named event handlers into that objectArray. How do I know which is which to properly remove them? Do I need to add extra member variables to test against? I.E. var.objectType = “bullet” or “plane” or “soldier” etc so I know which removeEventListener function to call? [import]uid: 75335 topic_id: 12755 reply_id: 46813[/import]