User input doesn't disappear when I going to another scene

Hello,

I have a problem, in my code creates a menu that is collected on the screen, when selected, the menu appears, and if I click on the button “publicar” moves to the scene, everything disappears under the user input box.

In general the input box doesn’t disappears when I tap a button and traslate to another scene.

I’d appreciate your help

Kevin

local function boton_publicar (event)

    if event.phase == “ended” then

        composer.gotoScene( “scenes.publicar”, {effect=“fade”, time=200, params = {resume=false}} )

    

    end

end

local menu_grafico = display.newImage(“imagenes/menu_grafico.png”, -37,65, true) menu_grafico.xScale = 0.15; menu_grafico.yScale = 0.15; --menu_grafico.y = display.contentHeight/7.5 sceneGroup:insert(menu_grafico) local publicar = display.newText(“Publicar Anuncio”, -45, 120, native.systemFont, 12); --local publicar = display.newText(“Publica un Anuncio”, 260, -15, native.systemFont, 10); sceneGroup:insert(publicar) publicar:addEventListener (“touch”, boton_publicar) local top10 = display.newText(“Top 10”, -45, 50, native.systemFont, 12); sceneGroup:insert(top10) local preferidas = display.newText(“Las Preferidas”, -45, 85, native.systemFont, 12); sceneGroup:insert(preferidas) local buscar = display.newImage(“imagenes/lupa.png”,-45, 15); buscar.xScale = 0.145; buscar.yScale = 0.145; sceneGroup:insert(buscar) local usuario = native.newTextField(-45, 15, 64, 29) usuario.size = 14 usuario.isVisible = false sceneGroup:insert(usuario) usuario:addEventListener( “userInput”, usuario ) --local lblFeedbackk = display.newText( “”, 250, 300, native.systemFont, 28 ) function usuario:userInput(event) --[[if event.phase == “began” then event.target.text = ‘’ lblFeedbackk.text = “waiting”]] if event.phase == “ended” then --lblFeedbackk.text = “Thank you” … " " … event.target.text if event.target.text == “leslie” then composer.gotoScene( “scenes.modelo”, “fade”, 840 ) usuario.isVisible = false end if event.target.text == “Leslie” then composer.gotoScene( “scenes.modelo”, “fade”, 840 ) usuario.isVisible = false end --[[elseif event.phase == “submitted” then lblFeedbackk.text = “Hello” … " " … event.target.text elseif event.phase == “editing” then lblFeedbackk.text = event.startPosition]] end end function buscar:tap( event ) native.setKeyboardFocus( nil ) end buscar:addEventListener(“tap”, buscar) function mover(event) if(event.phase == “began”)then diferenciaY = event.y - menu_grafico.y diferenciaX = event.x - menu_grafico.x --[[elseif(event.phase == “moved”)then --menu.y = event.y - diferenciaY menu_grafico.x = event.x - diferenciaX publicar.x = event.x - diferenciaX - 20 top10.x = event.x - diferenciaX - 20 preferidas.x = event.x - diferenciaX - 20 if (menu_grafico.x >= 75) then menu_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 elseif (menu_grafico.x <= -30) then menu_grafico.x = -30 publicar.x = -45 top10.x = -45 preferidas.x = -45 end --]] elseif (event.x > 110) then menu_grafico.x = -37 publicar.x = -45 top10.x = -45 preferidas.x = -45 usuario.x = -45 usuario.isVisible = false buscar.x = -45 elseif ((event.x >= 0) and (event.x <= 60)) then menu_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 usuario.isVisible = true usuario.x = 45 buscar.x = 92 end end menu_grafico:addEventListener(“touch”, mover)

local function boton\_publicar (event) if event.phase == "ended" then composer.gotoScene( "scenes.publicar", {effect="fade", time=200, params = {resume=false}} ) end end local menu\_grafico = display.newImage("imagenes/menu\_grafico.png", -37,65, true) menu\_grafico.xScale = 0.15; menu\_grafico.yScale = 0.15; --menu\_grafico.y = display.contentHeight/7.5 sceneGroup:insert(menu\_grafico) local publicar = display.newText("Publicar Anuncio", -45, 120, native.systemFont, 12); --local publicar = display.newText("Publica un Anuncio", 260, -15, native.systemFont, 10); sceneGroup:insert(publicar) publicar:addEventListener ("touch", boton\_publicar) local top10 = display.newText("Top 10", -45, 50, native.systemFont, 12); sceneGroup:insert(top10) local preferidas = display.newText("Las Preferidas", -45, 85, native.systemFont, 12); sceneGroup:insert(preferidas) local buscar = display.newImage("imagenes/lupa.png",-45, 15); buscar.xScale = 0.145; buscar.yScale = 0.145; sceneGroup:insert(buscar) local usuario = native.newTextField(-45, 15, 64, 29) usuario.size = 14 usuario.isVisible = false sceneGroup:insert(usuario) usuario:addEventListener( "userInput", usuario ) --local lblFeedbackk = display.newText( "", 250, 300, native.systemFont, 28 ) function usuario:userInput(event) --[[if event.phase == "began" then event.target.text = '' lblFeedbackk.text = "waiting"]] if event.phase == "ended" then --lblFeedbackk.text = "Thank you" .. " " .. event.target.text if event.target.text == "leslie" then composer.gotoScene( "scenes.chica\_2", "fade", 840 ) usuario.isVisible = false end if event.target.text == "Leslie" then composer.gotoScene( "scenes.chica\_2", "fade", 840 ) usuario.isVisible = false end --[[elseif event.phase == "submitted" then lblFeedbackk.text = "Hello" .. " " .. event.target.text elseif event.phase == "editing" then lblFeedbackk.text = event.startPosition]] end end function buscar:tap( event ) native.setKeyboardFocus( nil ) end buscar:addEventListener("tap", buscar) function mover(event) if(event.phase == "began")then diferenciaY = event.y - menu\_grafico.y diferenciaX = event.x - menu\_grafico.x --[[elseif(event.phase == "moved")then --menu.y = event.y - diferenciaY menu\_grafico.x = event.x - diferenciaX publicar.x = event.x - diferenciaX - 20 top10.x = event.x - diferenciaX - 20 preferidas.x = event.x - diferenciaX - 20 if (menu\_grafico.x \>= 75) then menu\_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 elseif (menu\_grafico.x \<= -30) then menu\_grafico.x = -30 publicar.x = -45 top10.x = -45 preferidas.x = -45 end --]] elseif (event.x \> 110) then menu\_grafico.x = -37 publicar.x = -45 top10.x = -45 preferidas.x = -45 usuario.x = -45 usuario.isVisible = false buscar.x = -45 elseif ((event.x \>= 0) and (event.x \<= 60)) then menu\_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 usuario.isVisible = true usuario.x = 45 buscar.x = 92 end end menu\_grafico:addEventListener("touch", mover)

The code is this. 

Thanks.

native.* objects are not managed by Composer. Even though you can add them to a group for movement purposes (i.e. they move with the group), they are otherwise un-managed. native.* objects are best created in scene:show()'s “did” phase and removed in scene:hide()'s “will” phase.

Rob

p

Hi Rob, I don’t understand.

Can you show me a example please.

Thanks

Pd: I have this code at the end of my scene

Kevin Teran

function scene:willEnter( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didEnter( event ) local sceneGroup = self.view composer.enableSwipe( true ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willExit( event ) local sceneGroup = self.view composer.enableSwipe( false ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- FUNCTION/CALLBACK DEFINITIONS -- ---------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willEnter( event ) elseif( willDid == "did" ) then self:didEnter( event ) end end function scene:hide( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willExit( event ) elseif( willDid == "did" ) then self:didExit( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Look at the edituser.lua scene here:

https://github.com/coronalabs-samples/business-app-sample

Thanks, I going to check the file.

local function boton\_publicar (event) if event.phase == "ended" then composer.gotoScene( "scenes.publicar", {effect="fade", time=200, params = {resume=false}} ) end end local menu\_grafico = display.newImage("imagenes/menu\_grafico.png", -37,65, true) menu\_grafico.xScale = 0.15; menu\_grafico.yScale = 0.15; --menu\_grafico.y = display.contentHeight/7.5 sceneGroup:insert(menu\_grafico) local publicar = display.newText("Publicar Anuncio", -45, 120, native.systemFont, 12); --local publicar = display.newText("Publica un Anuncio", 260, -15, native.systemFont, 10); sceneGroup:insert(publicar) publicar:addEventListener ("touch", boton\_publicar) local top10 = display.newText("Top 10", -45, 50, native.systemFont, 12); sceneGroup:insert(top10) local preferidas = display.newText("Las Preferidas", -45, 85, native.systemFont, 12); sceneGroup:insert(preferidas) local buscar = display.newImage("imagenes/lupa.png",-45, 15); buscar.xScale = 0.145; buscar.yScale = 0.145; sceneGroup:insert(buscar) local usuario = native.newTextField(-45, 15, 64, 29) usuario.size = 14 usuario.isVisible = false sceneGroup:insert(usuario) usuario:addEventListener( "userInput", usuario ) --local lblFeedbackk = display.newText( "", 250, 300, native.systemFont, 28 ) function usuario:userInput(event) --[[if event.phase == "began" then event.target.text = '' lblFeedbackk.text = "waiting"]] if event.phase == "ended" then --lblFeedbackk.text = "Thank you" .. " " .. event.target.text if event.target.text == "leslie" then composer.gotoScene( "scenes.chica\_2", "fade", 840 ) usuario.isVisible = false end if event.target.text == "Leslie" then composer.gotoScene( "scenes.chica\_2", "fade", 840 ) usuario.isVisible = false end --[[elseif event.phase == "submitted" then lblFeedbackk.text = "Hello" .. " " .. event.target.text elseif event.phase == "editing" then lblFeedbackk.text = event.startPosition]] end end function buscar:tap( event ) native.setKeyboardFocus( nil ) end buscar:addEventListener("tap", buscar) function mover(event) if(event.phase == "began")then diferenciaY = event.y - menu\_grafico.y diferenciaX = event.x - menu\_grafico.x --[[elseif(event.phase == "moved")then --menu.y = event.y - diferenciaY menu\_grafico.x = event.x - diferenciaX publicar.x = event.x - diferenciaX - 20 top10.x = event.x - diferenciaX - 20 preferidas.x = event.x - diferenciaX - 20 if (menu\_grafico.x \>= 75) then menu\_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 elseif (menu\_grafico.x \<= -30) then menu\_grafico.x = -30 publicar.x = -45 top10.x = -45 preferidas.x = -45 end --]] elseif (event.x \> 110) then menu\_grafico.x = -37 publicar.x = -45 top10.x = -45 preferidas.x = -45 usuario.x = -45 usuario.isVisible = false buscar.x = -45 elseif ((event.x \>= 0) and (event.x \<= 60)) then menu\_grafico.x = 75 publicar.x = 57 top10.x = 57 preferidas.x = 57 usuario.isVisible = true usuario.x = 45 buscar.x = 92 end end menu\_grafico:addEventListener("touch", mover)

The code is this. 

Thanks.

native.* objects are not managed by Composer. Even though you can add them to a group for movement purposes (i.e. they move with the group), they are otherwise un-managed. native.* objects are best created in scene:show()'s “did” phase and removed in scene:hide()'s “will” phase.

Rob

p

Hi Rob, I don’t understand.

Can you show me a example please.

Thanks

Pd: I have this code at the end of my scene

Kevin Teran

function scene:willEnter( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didEnter( event ) local sceneGroup = self.view composer.enableSwipe( true ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willExit( event ) local sceneGroup = self.view composer.enableSwipe( false ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- FUNCTION/CALLBACK DEFINITIONS -- ---------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willEnter( event ) elseif( willDid == "did" ) then self:didEnter( event ) end end function scene:hide( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willExit( event ) elseif( willDid == "did" ) then self:didExit( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Look at the edituser.lua scene here:

https://github.com/coronalabs-samples/business-app-sample

Thanks, I going to check the file.