Native textfield issue during scene change

Hi,
I am building a game that requires the user to choose between 2-4 items and then use a textfield to name each of them. I have simplified the code to the bare minimum to demonstrate the problem I am encountering (also to try to parse out the problem). The main.lua file transitions to the myMenu scene where the user clicks a button for the number of choices. This then goes to the catInput screen where each of the 2-4 categories can be given a name. Then the newscreen scene takes the names and places them on the screen and the game will run from there.
The issue I am running into is that when the catInput scene transitions to the newscreen the textfield stays on the screen. HOWEVER, if I bypass the myMenu scene then the textfield disappears along with the items that are part of the sceneGroup. When I re-add the myMenu scene back in the mix it gets messed up. I have double-checked everything I can think of for the past few days and am totally stumped. I have tried a number of variations I found in the forums to get native textboxes to disappear and none work with the myMenu scene included.
What am I missing? Thank you for any help!  code follows:

--main.lua ---------------------------------------------------- local composer = require ("composer") local widget = require("widget") display.setStatusBar(display.HiddenStatusBar) local function sceneTwo() --composer.getSceneName( "current" ) composer.gotoScene("myMenu", "fade", 400) end timer.performWithDelay(300, sceneTwo) -- myMenu.lua --------------------------------------------------- local composer = require ("composer") local scene = composer.newScene() local widget = require("widget") display.setStatusBar(display.HiddenStatusBar) local function sceneThree() local options = { effect = "fade", --time = 3000 } composer.gotoScene("newscreen", "fade" ) end local function goToGame2( self, event ) gameType=2 composer.gotoScene( "catInput", "fade" ) end function scene:create( event ) local sceneGroup = self.view testText = display.newText( "How many choices do you want?", 140, 20, native.systemFontBold, 16 ) sceneGroup:insert( testText ) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. --log:log("Scene created: " .. composer.getSceneName( "current" )) local buttonOne = widget.newButton { width = 200, left = display.contentWidth / 2 - 100, top = 100, id = "buttonOne", label = "Two Choices", fontSize = 25, labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0 } }, shape = "roundedRect", fillColor = { default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 } }, onEvent = goToGame2 } sceneGroup:insert(buttonOne) end -- ------------------------------------ function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end -- ------------------------------------ function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end -- ------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene ------- catInput.lua ----------------------------------------------- local composer = require ("composer") local scene = composer.newScene() local widget = require("widget") local function goToGame( self, event ) composer.gotoScene( "newscreen", "fade", 800 ) end function textListener( event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" or event.phase == "submitted" ) then textTwo = event.target.text end end function scene:create( event ) local sceneGroup = self.view timer.performWithDelay(1000, newText, 1) testText3 = display.newText( "Enter your choices here", 120, 40, native.systemFontBold, 16 ) sceneGroup:insert( testText3 ) local submitChoice = widget.newButton { width = 200, left = display.contentWidth / 2 - 100, top = 400, id = "submitChoice", label = "Submit Choices", fontSize = 25, labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0 } }, shape = "roundedRect", fillColor = { default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 } }, onEvent = goToGame } sceneGroup:insert(submitChoice) end -- ------------------------------------ function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then choiceField = native.newTextField( 150, 150, 180, 30 ) sceneGroup:insert(choiceField) choiceField:addEventListener( "userInput", textListener ) ---------- the choice fields end end -- ------------------------------------ function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then function killBox( self, event ) testText4 = display.newText( "test", 140, 60, native.systemFontBold, 16 ) if (choiceField ~= nil) then choiceField:removeSelf() choiceField = nil native.setKeyboardFocus( nil ) end end timer.performWithDelay(10, killBox, 1) testText5 = display.newText( "test2", 140, 80, native.systemFontBold, 16 ) end end -- ------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene -- newscreen.lua--------------------------------------------------------------------- local composer = require ("composer") local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- ------------------------------------ function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then local twoTotal = 0 twoTotalText = display.newText( textTwo .." - " .. twoTotal, 0, 0, native.systemFontBold, 16 ) twoTotalText:setTextColor( 255, 60, 60, 190 ) twoTotalText.x = 220; twoTotalText.y = 400; elseif ( phase == "did" ) then end end -- ------------------------------------ function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end -- ------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

Have you already tested removing the textField explicitly? I just tested it and it appears to remove as normal in the “did” phase. Perhaps the issue is with the “killBox” function.

I had tried that. If I put choiceField:removeSelf() explicitly in the did phase of the hide event I get an error:attempt to index global ‘choiceField’ (a nil value). The textField removes fine if it doesn’t go through the myMenu scene first so I think the killBox function is OK. I put that in there to try to get the removeSelf to fire without an error. Really stumped.

An update: It appears that the textField box has trouble clearing any time there is more than a couple of scene transitions. I added the textField a scene earlier in the myMenu scene, went right to the final scene and the textField went away just fine. So main-> myMenu ->newscreen works fine but main->myMenu-> catInput ->newscreen does not. The bold is where the textField code is located. Any time there is an extra scene between the main.lua and the file with the textField code It won’t clear the white box. The input clears but the box stays. What am I doing wrong?

Figured it out. In whatever scene that comes after the textbox I needed to put composer.removeScene( “previous” ) in the function scene:create( event ) where “previous” is the name of the scene with the texbox

You also have to place it after function scene:show( event ) otherwise the problem is back when flicking on and off for the second time.

Have you already tested removing the textField explicitly? I just tested it and it appears to remove as normal in the “did” phase. Perhaps the issue is with the “killBox” function.

I had tried that. If I put choiceField:removeSelf() explicitly in the did phase of the hide event I get an error:attempt to index global ‘choiceField’ (a nil value). The textField removes fine if it doesn’t go through the myMenu scene first so I think the killBox function is OK. I put that in there to try to get the removeSelf to fire without an error. Really stumped.

An update: It appears that the textField box has trouble clearing any time there is more than a couple of scene transitions. I added the textField a scene earlier in the myMenu scene, went right to the final scene and the textField went away just fine. So main-> myMenu ->newscreen works fine but main->myMenu-> catInput ->newscreen does not. The bold is where the textField code is located. Any time there is an extra scene between the main.lua and the file with the textField code It won’t clear the white box. The input clears but the box stays. What am I doing wrong?

Figured it out. In whatever scene that comes after the textbox I needed to put composer.removeScene( “previous” ) in the function scene:create( event ) where “previous” is the name of the scene with the texbox

You also have to place it after function scene:show( event ) otherwise the problem is back when flicking on and off for the second time.