Hi. I made a simple test wich proves that removeEventListernet does not work.
It simply shows 2 buttons and 1 variable (text). One button for adding +1 to the variable and update the screen (show the new value of the variable), and one button for (try) stop the other button to work. But it can’t! Why?
variable=1
function the_test()
local button_plus
local button_stop
local function show_everything()
display.newImage(“background.png”,0,0)
button_plus=display.newImage(“button_plus.png”, 45, 375 )
button_stop=display.newImage(“button_stop.png”,147,270)
local myText = display.newText( "variable = " … variable, 0, 0, “Arial”, 40 )
end
show_everything()
local function variable_update()
variable=variable+1
show_everything()
return true
end
local function stop_variableUpdates()
button_plus:removeEventListener( “tap”, variable_update ) <----- does not work!!!
return true
end
button_plus:addEventListener( “tap”, variable_update )
button_stop:addEventListener( “tap”, stop_variableUpdates )
end
—start here:
the_test()
I press the button_stop, so it calls the function stop_variableUpdates() wich contains:
button_plus:removeEventListener( “tap”, variable_update )
So the button_plus must stop working…
But if I press it, the variable still continues increase…
Why this is not working? How can I fix that?
Please help me. Thanks!