Text Fields stays onscreen when moving to another scene

I made an app with 2 scenes, that in each of them there is textFields created by native.newTextField, and when I call composer.gotoScene the textFields stays on the screen in the next scene. It happens only with the textFields, not the buttons and texts, and only in my android device, not the simulator. Any idea why is it happening?

Native objects (native.*) do not work with display groups since they are not part of the OpenGL canvas. Therefore

storyboard and Composer cannot manage them.  You need to create them in enterScene (or scene:show) events while removing them in the exitScene (scene:hide) events.

Rob

Thank you Rob! Now I get it! But that is causing anoher problem… if I’m writing something in the textfield and moving to another scene and back to the scene, obviously the text is gone, because the textfield was re-created. How can i make the

scene remember the text that was written in the textfield when I left it?

You have a couple of options.  If you know you’re coming back to the scene with the textFields, then simply set their visibility (.isVisible) to false when you exit the scene, and set it to true when you enter the scene.  That way they should stay around.  Since they are not part of the scene’s managed objects, they are safe in between scene creation and destruction.  The second option is to save the data from the fields before you destroy them and then set the values back when you re-create the fields.

Rob

Hi assahfass, Check out newEditField from widgetstown.com - the sample app shows how to preserve the text fields accross scenes automatically, without all the overhead of removing and re-adding fields

Native objects (native.*) do not work with display groups since they are not part of the OpenGL canvas. Therefore

storyboard and Composer cannot manage them.  You need to create them in enterScene (or scene:show) events while removing them in the exitScene (scene:hide) events.

Rob

Thank you Rob! Now I get it! But that is causing anoher problem… if I’m writing something in the textfield and moving to another scene and back to the scene, obviously the text is gone, because the textfield was re-created. How can i make the

scene remember the text that was written in the textfield when I left it?

You have a couple of options.  If you know you’re coming back to the scene with the textFields, then simply set their visibility (.isVisible) to false when you exit the scene, and set it to true when you enter the scene.  That way they should stay around.  Since they are not part of the scene’s managed objects, they are safe in between scene creation and destruction.  The second option is to save the data from the fields before you destroy them and then set the values back when you re-create the fields.

Rob

Hi assahfass, Check out newEditField from widgetstown.com - the sample app shows how to preserve the text fields accross scenes automatically, without all the overhead of removing and re-adding fields