Hi,
I use a switch in a scene overlay which I use as checkbox as described here.
I use an image in the background to detect taps on it to be able to close the overlay:
-- alpha overlay local alphaOverlay = display.newRect(mainGroup, ssk.core.centerX, ssk.core.centerY, display.actualContentWidth, display.actualContentHeight) alphaOverlay:setFillColor(unpack(\_BLACK\_)) alphaOverlay.alpha = 0.4 local function backgroundTouchListener(event) composer.hideOverlay("fade", 200) return true end alphaOverlay:addEventListener("tap", backgroundTouchListener)
Button presses do not close the overlay because I use “return true” in the tap handler. This works fine:
local function feedbackButtonHandler(event) doAnything() return true -- Prevents tap/touch propagation to underlying objects end feedbackButton = display.newImageRect(mainGroup, "scene/menu/img/button\_mail.png", buttonWidth, buttonHeight) feedbackButton.x, feedbackButton.y = overlayBackground.x, analyticsCheckbox.y + 50 feedbackButton:addEventListener("tap", feedbackButtonHandler)
Switch event handling:
local checkboxSheet = graphics.newImageSheet("scene/settings/img/checkbox\_spritesheet.png", { width = 36, height = 36, numFrames = 2, sheetContentWidth = 73, sheetContentHeight = 36 }) local function onTutorialSwitchPress() doAnything() end tutorialCheckbox = widget.newSwitch( { style = "checkbox", width = 25, height = 25, onPress = onTutorialSwitchPress, sheet = checkboxSheet, frameOff = 1, frameOn = 2 } ) tutorialCheckbox.x, tutorialCheckbox.y = overlayBackground.x + width/4 , tutorialText.y tutorialCheckbox:setState({isOn = myData.settings.firstTimeUseTutorial}) mainGroup:insert(tutorialCheckbox)
But if the checkbox is pressed the overlay gets closed.
My question is if I can prevent tap/touch propagation to underlying objects on my checkbox?