How do you remove an Event Listener?

Having problems removing an event listener. The code below works fine and removes the listener as soon as it is created.

function otherTouch( event )  
 print( "otherTouch: event(" .. event.phase .. ") ("..event.x..","..event.y..")" .. tostring(event.id) )  
 end  
  
 Runtime:addEventListener( "touch", otherTouch )  
 Runtime:removeEventListener( "touch", otherTouch )  

but if I try and call this from a function it does not remove the listener. I do not suspect this has anything to do with it, but I am using Director to change screens.

This does not work:

[code]
local function btnRewindT ( event )
if event.phase == “release” then
print(“btnRewind stopping Listener”)
Runtime:removeEventListener(“touch”, otherTouch )
end
end

function otherTouch( event )
print( “otherTouch: event(” … event.phase … “) (”…event.x…","…event.y…")" … tostring(event.id) )
end

Runtime:addEventListener( “touch”, otherTouch )

[/code] [import]uid: 52906 topic_id: 9439 reply_id: 309439[/import]

otherTouch is not known inside btnRewindT.
Changing the order of your functions should make your problem go away:

[lua]local function otherTouch( event )
– do stuff
end

local function btnRewindT ( event )
if event.phase == “release” then
print(“btnRewind stopping Listener”)
Runtime:removeEventListener(“touch”, otherTouch )
end
end

Runtime:addEventListener( “touch”, otherTouch )[/lua] [import]uid: 51516 topic_id: 9439 reply_id: 34576[/import]

Seth,

I p@##%ed away 4 hours this morning trying to figure this out and you just set me free.

Lots of love your way…thanks!

Dave [import]uid: 52906 topic_id: 9439 reply_id: 34588[/import]