[RESOLVED] Checkboxes not removed on scene change

Hello everyone,

I am unable to remove the checkboxes created on one scene while changing to the next. 

I have isolated the area where the problem is occurring and am unable to figure out the problem. 

Here is my code (my apologies for the length):

main.lua 

display.setStatusBar( display.HiddenStatusBar ) local storyboard = require "storyboard" storyboard.gotoScene( "page1", "fade", 400)

page1.lua

local storyboard = require "storyboard" local scene = storyboard.newScene() local widget = require( "widget" ) local screen = display.newGroup() local checks = display.newGroup() --forcheckboxes local function menuClick( event ) if event.phase == "ended" then storyboard.gotoScene( "page2", "fade", 800 ) return true end end for i = 1 ,5,1 do checks[i] = widget.newSwitch { left = 60, -- coordinates of top left corner top = 100\*i, style = "checkbox", initialSwitchState = false } end screen:insert(checks) menu = widget.newButton{ label = "Page 2", onEvent = menuClick } screen:insert(menu) function scene:enterScene( event ) storyboard.removeAll() end function scene:exitScene( event ) screen:removeSelf() end scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) return scene 

page2.lua

local storyboard = require "storyboard" local scene = storyboard.newScene() local widget = require( "widget" ) local screen = display.newGroup() local checks = display.newGroup() local function menuClick( event ) if event.phase == "ended" then storyboard.gotoScene( "page1", "fade", 800 ) return true end end menu = widget.newButton{ label = "Page 1", onEvent = menuClick } function scene:enterScene( event ) storyboard.removeScene( storyboard.getPrevious()) end function scene:exitScene( event ) screen:removeSelf() end scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) return scene

The checkboxes created in the loop are present only in page1. They are not removed when going to page2. I am new to Corona and my apologies if i am missing something obvious.

Thanks in advance.

I found the error i was making. The buttons were not properly inserted in the display group.

Correction:

for i = 1 ,5,1 do local checkbox = widget.newSwitch { left = 60, -- coordinates of top left corner top = heading.contentHeight + (i\*60), style = "checkbox", initialSwitchState = false, --onPress = onSwitchPress } checks:insert( checkbox) end

Then i removed the displaygroup

For those who may run into this in the future, you can only insert a display object into a display group.  You cannot insert a table full of display objects into a display group.  MayBee’s solution of bringing the checks:insert() inside the for loop to work on each individual widget was the right solution.

I found the error i was making. The buttons were not properly inserted in the display group.

Correction:

for i = 1 ,5,1 do local checkbox = widget.newSwitch { left = 60, -- coordinates of top left corner top = heading.contentHeight + (i\*60), style = "checkbox", initialSwitchState = false, --onPress = onSwitchPress } checks:insert( checkbox) end

Then i removed the displaygroup

For those who may run into this in the future, you can only insert a display object into a display group.  You cannot insert a table full of display objects into a display group.  MayBee’s solution of bringing the checks:insert() inside the for loop to work on each individual widget was the right solution.