Radio buttons and check boxes remain after scene change

I have already read that article (and many others) I could not find answers there thus I posted this article.

If you look at my code all my button creations are already in the scene creation sections so I’m not sure how else to place it?

Richtornado, I have clear the createView method to show you the part of the radio button, to illustrate where the problem is. (the code is not tested, just reformated quickly your code). Again, your bug was that you never added your group!

function scene:create( event ) -- this is the group of your view local mainGroup = self.view -- Create a group for the radio button set local radioGroup = display.newGroup() -- you must insert your radio group into your main group (view) mainGroup:insert(radioGroup) -- you could simplify your code by creating a generic method local function createSwitchButton( group, id, left, top, style, initialState) -- Handle press events for the buttons local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end -- Create a radio button local switchButton = widget.newSwitch( { left = left, top = top, style = style, id = id, initialSwitchState = initialState, onPress = onSwitchPress } ) group:insert( switchButton ) end createSwitchButton( radioGroup, "RadioButton1", 150, 200, "radio", true) createSwitchButton( radioGroup, "RadioButton2", 250, 200, "radio", false) end

Thank you for the reply.

I actually removed the radio button and only added checkboxes.

I’m still getting the error that the checkboxes are still visible on the next scene.

I  have placed the in the scene create section but nothing has changed.

this is my entire core for this scene. Everything works but the check boxes remain in the next scene.

local composer = require ("composer") local scene = composer.newScene() local widget = require( "widget" ) -- Handle press events for the checkbox local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end local function changeScene1() local options = { effect = "crossFade", time = 100 } composer.gotoScene( "scene1", options ) end local function changeScene4() local options = { effect = "crossFade", time = 800 } composer.gotoScene( "scene4", options ) end function scene:create( event ) mainGroup = self.view local image2 = display.newImageRect("Slide002.png", display.contentWidth, display.contentHeight) image2.anchorX = 0 image2.anchorY = 0 image2.alpha = 1 image2:toBack( ) local rectScore2 = display.newRect( 850, 700, 255, 125 ) -- push this rectangle to increase score mainGroup:insert(rectScore2) rectScore2:setFillColor( 1, 1, 1 ) rectScore2.alpha = 1 rectScore2:addEventListener("touch", changeScene4 ) local rectReset = display.newRect( 80, 40, 130, 50 ) --rectReset:setFillColor( 1, 0, 0 ) -- push this rectangle to increase score mainGroup:insert(rectReset) rectReset:addEventListener("touch", changeScene1 ) rectReset.alpha = 1 -- Create the widget local checkboxButton = widget.newSwitch( { left = 350, top = 555, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) -- Create the widget local checkboxButton1 = widget.newSwitch( { left = 350, top = 605, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) mainGroup:insert (image2) end function scene:show( event ) local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end function scene:hide( event ) local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

@nmichaud I think i understand and was able to get your example to work in my page.

Now i’m just not sure how to create a group for the individual Check Box buttons?

If you take the example I have provided, you do not need to create another group for checkbox. You only need to create group for radiobutton when you want to group them logically.

Simply call the same method like this using your main view group:  createSwitchButton( mainGroup, “idOfYourCheckBox”, 150, 200, “checkbox”, true)

as long as every object is ultimately inserted into the scenes view it will work fine.  In your scenario, and most tbh, toBack() and toFront() never need calling.

an object inserted into a display group (if you are not using indexing) will always be at the top.

Finally got it to work.

Thank you so much guys.

You accept your own broken answer as the solution?  gee so glad we took the time to help you!

Oops sorry, I checked on the wrong box by mistake.