How can i remove the event listener form a newSwitch ?
local function onSwitchPress( event ) local switch = event.target print("witch Press") -- remove event listener ?? end local onOffSwitch = widget.newSwitch { x = dpw - dpw/2, y = dph - dph/2, style = "onOff", id = "onOffSwitch", onPress = onSwitchPress } onOffSwitch:setState( { isOn=true, isAnimated=true} )
Alex10
July 21, 2015, 6:51pm
2
Can you set a flag that keeps the listener from being called?
local flagIsSet = false timer.performWithDelay( 3000, function() flagIsSet = true print(" flagIsSet is "..tostring(flagIsSet)) timer.performWithDelay(1000, function() flagIsSet = false print(" flagIsSet is "..tostring(flagIsSet)) end, 1) end, 20) local function onSwitchPress( event ) local switch = event.target if flagIsSet == true then print("catching unhandled switch press here") else print("Switch Press") end end
this seems to work
flagIsSet = true local function onSwitchPress( event ) local switch = event.target if flagIsSet == true then print("catching unhandled switch press here") flagIsSet = false else print("Switch Press") end end
Alex10
July 21, 2015, 6:51pm
4
Can you set a flag that keeps the listener from being called?
local flagIsSet = false timer.performWithDelay( 3000, function() flagIsSet = true print(" flagIsSet is "..tostring(flagIsSet)) timer.performWithDelay(1000, function() flagIsSet = false print(" flagIsSet is "..tostring(flagIsSet)) end, 1) end, 20) local function onSwitchPress( event ) local switch = event.target if flagIsSet == true then print("catching unhandled switch press here") else print("Switch Press") end end
this seems to work
flagIsSet = true local function onSwitchPress( event ) local switch = event.target if flagIsSet == true then print("catching unhandled switch press here") flagIsSet = false else print("Switch Press") end end