Input text remains when changing scenes

I created an app that asks the user for their name but when the app goes to the next scene the text input box remains visible on all other scenes. I’ve tried to add “mainGroup:insert(nameField)” but it does not work (often giving me errors). any suggestions? Thanks in advance.

local myText = display.newText( "Enter your full name", 500, 350, native.systemFont, 38 ) local nameField = native.newTextField( 500, 400, 320, 36 ) nameField.inputType = "name" mainGroup:insert(myText) mainGroup:insert(nameField)

Where is mainGroup defined?

There is no global variable by that name.

Are you following a tutorial and if so, can you provide a link to it?

Try this (may be wrong if you’re following a tutorial):

local mainGroup = display.newGroup() local myText = display.newText( "Enter your full name", 500, 350, native.systemFont, 38 ) local nameField = native.newTextField( 500, 400, 320, 36 ) nameField.inputType = "name" mainGroup:insert(myText) mainGroup:insert(nameField)

I’m following https://docs.coronalabs.com/api/type/TextField/

but there is nothing in there about changing scenes or groups (that I can see).

I’ve also been all over Google, a lot of info on creating a text box but not much beyond that that I can find.

I ended up useing nameField2.isVisible = true and on the next scene nameField2.isVisible = false.

It seems to have worked but I don’t know if that’s the correct method?

  1. That documentation is about text fields.  You need to read the composer.* documenation to understand composer and scene management.

  2. That wasn’t a link to the example code.  I’m not going to dig for it, so I’ll assume either you only grabbed a snippet or didn’t get it all.  In any case, continue reading for help and advice…

  3. You are not adding your text fields to the scene group.  However, it isn’t that simple.  Text fields are native objects and need to be hidden or removed as part of the scene transition.  This is due to the nature of how the composer.* scene manager actually handles groups.

  4. Here are docs and many examples of using composer.*, including one with text fields (#13)

Tip 1: I’m pretty sure Corona comes with at least one or two composer examples as well (as part of the example code bundled with the simulator).

Tip 2: You would probably be well served both of my gits in their entirety:

One last tip.

You said ‘I’ve also been all over Google’.  For improved results, you may want to consider these search types:

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

It has examples of using text fields with Composer.

Rob

Thanks everyone. It seems to work great now :slight_smile:

I’ll be reading all the great information.

Where is mainGroup defined?

There is no global variable by that name.

Are you following a tutorial and if so, can you provide a link to it?

Try this (may be wrong if you’re following a tutorial):

local mainGroup = display.newGroup() local myText = display.newText( "Enter your full name", 500, 350, native.systemFont, 38 ) local nameField = native.newTextField( 500, 400, 320, 36 ) nameField.inputType = "name" mainGroup:insert(myText) mainGroup:insert(nameField)

I’m following https://docs.coronalabs.com/api/type/TextField/

but there is nothing in there about changing scenes or groups (that I can see).

I’ve also been all over Google, a lot of info on creating a text box but not much beyond that that I can find.

I ended up useing nameField2.isVisible = true and on the next scene nameField2.isVisible = false.

It seems to have worked but I don’t know if that’s the correct method?

  1. That documentation is about text fields.  You need to read the composer.* documenation to understand composer and scene management.

  2. That wasn’t a link to the example code.  I’m not going to dig for it, so I’ll assume either you only grabbed a snippet or didn’t get it all.  In any case, continue reading for help and advice…

  3. You are not adding your text fields to the scene group.  However, it isn’t that simple.  Text fields are native objects and need to be hidden or removed as part of the scene transition.  This is due to the nature of how the composer.* scene manager actually handles groups.

  4. Here are docs and many examples of using composer.*, including one with text fields (#13)

Tip 1: I’m pretty sure Corona comes with at least one or two composer examples as well (as part of the example code bundled with the simulator).

Tip 2: You would probably be well served both of my gits in their entirety:

One last tip.

You said ‘I’ve also been all over Google’.  For improved results, you may want to consider these search types:

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

It has examples of using text fields with Composer.

Rob

Thanks everyone. It seems to work great now :slight_smile:

I’ll be reading all the great information.