Hi guys i can’t figure out how to get these native.newTextField’s to disappear, they’re in a scenGroup and when i switch scenes all the rest work perfectly fine, these text file don’t get off the screen tho… any suggestion ? i was thinkg about .isVisible = false could it work ? thank you all :rolleyes:
You have to remove it manually with removeSelf() or display.remove(). Read the documentation!
https://docs.coronalabs.com/api/library/native/newTextField.html
Gotchas
Presentation of native controls in the Corona Simulator can only be an approximation of the actual device. Always test on a device and assume that the behavior/appearance on devices is correct. In particular, the internal margins in text fields on some devices may be much larger than expected, reducing the space available for the actual text and making the font appear to be very small because it is being auto-sized into a small region. Increasing the font size won’t help since there will not be space available for the font, so increasing the height of the text field is a better approach. See object:resizeHeightToFitFont() and object:resizeFontToFitHeight() for convenient ways to make these kind of adjustments. Note that the internal margins of text fields are not adjustable.
Native text fields are not part of the OpenGL canvas and do not obey the display object hierarchy, so they will always appear in front of normal display objects including images, text, and vector objects. However, native text fields can be “inserted” (object:insert()) into Corona display groups and they will move in unison with that group.
To remove a native text field from the display, use object:removeSelf().
The native.setKeyboardFocus() API is used to show and hide the keyboard used for text input (applies to device and Xcode iOS Simulator only).
On Android, due to the fact that Corona runs on multiple threads, getting the .text value of a TextField immediately after setting it will not return the correct value. This action should be performed following a short timer or during the next time step.
I was about to reply after looking at your project. I guess you have figured out that you never insert objGrp into sceneGroup so Composer will not remove that for you? You will also need to add Sfondo into sceneGroup before anything else or it will appear on top.
You also have an error in menu3.lua where you are not supplying a width or height for the image.
All this swapping between objGrp and objGrp2 should now be unnecessary if you add EVERYTHING to sceneGroup.
i already tried it… but when i switch from menu1 to menu2 then back to menu 1 and then menu2 i get this error
As I’ve said before, trying to build this calculator app across multiple scenes is a really ambitious attempt when you are new to programming and haven’t got the basics down.
In this case the object is nil, therefore the function removeSelf doesn’t exist. I think I’ve helped you as much as I can, because we can fix the next 20 mistakes but the problem is I don’t think you’re learning from any of them.
At some point you have to be able to interpret the error messages and take some basic steps to identify the problem.
The calculator is finished, and i figured out how to switch all the scenes. After this my app will be done… I just don’t get how to remove them if they’re already in a group
Hi i tried this:
[lua]
local numericField
function scene:show (event)
local sceneGroup = self.view
local phase = event.phase
if (phase == “will”) then
– mycode
if (phase == “did” ) then
numericField = native.newTextField ( 162 , 90 ,315 , 50 )
numericField.text = “”
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
display.remove(numericField)
numericField= nil
elseif ( phase == “did” ) then
– Code here runs immediately after the scene goes entirely off screen
end
end[/lua]
And now when i switch scenes it disappears but after 4 times i switch in between the menus it stays on screen??
- try to add numericField:removeSelf() there, where you switch to next scene:
[lua]
numericField:removeSelf()
composer.gotoScene(“Scene name”)
[/lua]
- Why you added local numericField and only after that numericField = native.newTextField(162,90,315,50)?
You could just local numericField = native.newTextField(162,90,315,50)