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?

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.



So, I'm doing something in a loop

loop {
local var = newImageRect(...)
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)

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?

views:923 update:2011/9/28 9:01:40
corona forums © 2003-2011