Runtime:removeEventListener not work (it is in scope)

I have tried everything but nothing seems to make the eventListener to stop to work even when page changes.

My project uses Director (resumed code below):

module(..., package.seeall)   
  
 function new()   
 local numPages = 23   
 local menuGroup = display.newGroup()   
 local curPage = 23   
 local shakeMe23  
 local act\_action\_930   
  
 local drawScreen = function()   
 local onpageDownTouch = function(event)   
 if event.phase=="ended" then   
 local myClosure\_switch = function()   
 Runtime:removeEventListener("accelerometer", shakeMe23)  
  
 director:changeScene( "page\_19", "moveFromRight" )   
 end   
 timerStash.newTimer\_003 = timer.performWithDelay(300, myClosure\_switch, 1)   
 end   
 end   
 pageDown = ui.newButton{   
 defaultSrc=imgDir.."p23\_pagedown.png",   
 defaultX = 39,   
 defaultY = 48,   
 overSrc=imgDir.."p23\_pagedown.png",   
 overX = 39,   
 overY = 48,   
 onRelease=onpageDownTouch,   
 id="pageDownButton"   
 }   
  
 pageDown.x = 29; pageDown.y = 39; pageDown.alpha = 1; pageDown.oldAlpha = 1   
 menuGroup:insert(pageDown)   
 menuGroup.pageDown = pageDown   
  
 --SHAKE   
 function shakeMe23 (e)   
 if(e.isShake == true) then   
 act\_action\_930()   
 end   
 end   
 Runtime:addEventListener("accelerometer", shakeMe23)   
   
   
 --ACTIONS functions   
 function act\_action\_930 (event)   
 director:changeScene( "page\_"..curPage)   
  
 end   

Issue is, even when I change pages, the “accelerometer” event keeps calling “shakeMe23” function.

Any ideas? [import]uid: 4883 topic_id: 19900 reply_id: 319900[/import]

if you cant remove listener then you can use an “if” statement for runtime function and then change variable when needed and function will stop [import]uid: 16142 topic_id: 19900 reply_id: 77309[/import]

When you do the change in myClosure_switch you remove the listener

local myClosure_switch = function()
Runtime:removeEventListener(“accelerometer”, shakeMe23)
director:changeScene( “page_19”, “moveFromRight” )
end
But when you change scene due to a shake, you do not:

function shakeMe23 (e)
if(e.isShake == true) then
act_action_930()
end
end

try
function shakeMe23 (e)
if(e.isShake == true) then
Runtime:removeEventListener(“accelerometer”, shakeMe23)
act_action_930()
end
end

[import]uid: 108660 topic_id: 19900 reply_id: 77316[/import]

jeff472,
I don’t want to remove the listener in the shakeMe23 function because in this case the user will be kept in the page. I need the listener removed only with the buttons are hit (in this case the app will move to another page).

The solution you provide only work during the first shake (after that, the shakeMe function disabled the accelerometer. [import]uid: 4883 topic_id: 19900 reply_id: 77338[/import]

Found a workaround using director:changeScene(director:getCurrScene())

however, I couldn’t figure out how to cancel the listener… [import]uid: 4883 topic_id: 19900 reply_id: 77399[/import]