Removing of eventHandlers

Hi,
just wanted to understand the following

say,

 local test = display.newRact(10,10,100,100)  
 test:setFillColor(255,0,0)  
  
 local handleTouch = function ( event )  
 if "ended" == event.phase then   
 print ("This one time only")  
 end  
  
 test:removeEventListener ( "touch", handleTouch )  
 end  
  
 test:addEventListener ( "touch", handleTouch )  

Can we have a eventListener negator?
To remove an eventListener the function, etc has to be known or be the same. why can’t it just be a {} to remove/disable the event handler or a nil.

so instead of removeEventListener, it would be like

test:setEventListener ( touch,nil )  

or

test:setEventListener ( "touch", {} )  

which is much easier and this way it can be deactivated from the calling event itself and not cause crashes.

cheers, [import]uid: 3826 topic_id: 7465 reply_id: 307465[/import]

This is VERY interesting. Have you done any testing to verify that this works? [import]uid: 7849 topic_id: 7465 reply_id: 26565[/import]

@jon,
the second part was a suggestion, not the results of an experiment.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 7465 reply_id: 26566[/import]

note: you’re trying to remove your handler 3 times (it’s called in every phase). but that’s not the problem… your function needs to see itself so you need to predefine it with a forward reference

[lua]local test = display.newRect(10,10,100,100)
test:setFillColor(255,0,0)

local handleTouch – forward reference

function handleTouch(event) – still actually local
print(“touch:”…event.phase)
if “ended” == event.phase then
print (“This one time only”)
test:removeEventListener ( “touch”, handleTouch ) – can see local reference now
end
end

test:addEventListener ( “touch”, handleTouch )[/lua] [import]uid: 6645 topic_id: 7465 reply_id: 26609[/import]