how to get an event listener to only work under certain "if" conditions

for instance having the event listener only work if a statement is true, and if not then it will no longer respond to clicks or whatever.
By statement for instance I started out saying red = true, and after the clicking on the object (a button) it refers it to the function buttonHandler and one of the things this function does is sets the statement to red = false. This way the next time someone clicks on the button, red will now equal false which will keep the listener from referring to buttonHandler. Here is a segment of my work so far:

red = true
function buttonHandler (e)
if(e.phase == “began”) then
audio.play (knock);
physics.setGravity (0, -3);
physics.addBody (button, “static”, {bounce= 0.5})
red = false

end

–elseif (red = false) then
–audio.play (knock);

end

button: addEventListener (“touch”, buttonHandler)
[import]uid: 35535 topic_id: 6587 reply_id: 306587[/import]

do you want it to actually remove the button handler or just do something different? [import]uid: 6645 topic_id: 6587 reply_id: 22842[/import]

I want the buttonHandler to do something different depending on whether or not red = true or red = false [import]uid: 35535 topic_id: 6587 reply_id: 22872[/import]

[lua]local red = true

local function buttonHandler (e)

if(e.phase == “began”) then

if(red == true) then

audio.play (knock);
red = false

elseif (red == false) then

audio.play (knock);

end
end
end

button: addEventListener (“touch”, buttonHandler)[/lua] [import]uid: 6645 topic_id: 6587 reply_id: 22957[/import]

Thanks so much for your help, it worked! [import]uid: 35535 topic_id: 6587 reply_id: 22996[/import]