Is it possible to temporarily disable a user's interaction with widget.newSwitch?

 I don’t want to remove the widget from view, I just want to temporarily inactivate it until one of my functions specifies it to resume “listening” for user input. So I’m thinking I need to do something similar to disabling the event listener for my widget.newSwitch (onOff slider button). However, I don’t know what the coding for the widget looks like, otherwise I was thinking I might be able to play around with some of the variables that it uses. 

Any ideas?

Here’s the link to the doc:

https://docs.coronalabs.com/api/library/widget/newSwitch.html

You could place an invisible rect (alpha 0.01) on top that intercepts all the touch events on that area of the screen.

local coverButton = display.newRect(switchVariableHere.x, switchVariableHere.y, switchVariableHere.width, switchVariableHere.height)
coverButton.alpha=.000001
coverButton:addEventListener(“touch”, function() return true end)

Thanks for the help guys, works great! 

Also @scottrules44, corona apparently doesn’t like your alpha of 0.000001 :stuck_out_tongue: , I guess it internally rounds that to 0. I found that 0.01 was the smallest non-zero alpha value you could use.  

Also if you don’t mind, I never understood what return true actually means. I’m assuming that when a user presses the screen, that “stimulus” travels all the was down into multiple layers until it hits the last layer and a “true” statement returns? AKA if after one layer deep we tell the device that yes, it “returned true”, then the stimulus will halt its downward traveling motion?

Return true prevents the touch event from continuing down the layers of display objects as shown in this thread

https://forums.coronalabs.com/topic/64746-multilayered-intersection-with-events/

https://youtu.be/tdq5yqM1-Us
Go to
3:00

You can do a totally invisible rect by setting .isVisible = false but you also have to set .isHitTestable = true for it to catch the touch/tap events.

local blockTouch = display.newRect( 100, 100, 50, 50 ) blockTouch.isVisible = false blockTouch.isHitTestable = true

Or you could forego making it invisible and do something like this:

-- black background blockTouch:setFillColor( 0, 0, 0, 0.5 ) blockTouch.blendMode = "multiply" -- white background blockTouch:setFillColor( 1, 1, 1, 0.5 ) blockTouch.blendMode = "screen"

That way you’re simultaneously  providing a visual clue that the switch is disabled.

Rob

You could place an invisible rect (alpha 0.01) on top that intercepts all the touch events on that area of the screen.

local coverButton = display.newRect(switchVariableHere.x, switchVariableHere.y, switchVariableHere.width, switchVariableHere.height)
coverButton.alpha=.000001
coverButton:addEventListener(“touch”, function() return true end)

Thanks for the help guys, works great! 

Also @scottrules44, corona apparently doesn’t like your alpha of 0.000001 :stuck_out_tongue: , I guess it internally rounds that to 0. I found that 0.01 was the smallest non-zero alpha value you could use.  

Also if you don’t mind, I never understood what return true actually means. I’m assuming that when a user presses the screen, that “stimulus” travels all the was down into multiple layers until it hits the last layer and a “true” statement returns? AKA if after one layer deep we tell the device that yes, it “returned true”, then the stimulus will halt its downward traveling motion?

Return true prevents the touch event from continuing down the layers of display objects as shown in this thread

https://forums.coronalabs.com/topic/64746-multilayered-intersection-with-events/

https://youtu.be/tdq5yqM1-Us
Go to
3:00

You can do a totally invisible rect by setting .isVisible = false but you also have to set .isHitTestable = true for it to catch the touch/tap events.

local blockTouch = display.newRect( 100, 100, 50, 50 ) blockTouch.isVisible = false blockTouch.isHitTestable = true

Or you could forego making it invisible and do something like this:

-- black background blockTouch:setFillColor( 0, 0, 0, 0.5 ) blockTouch.blendMode = "multiply" -- white background blockTouch:setFillColor( 1, 1, 1, 0.5 ) blockTouch.blendMode = "screen"

That way you’re simultaneously  providing a visual clue that the switch is disabled.

Rob