sceneGroup refuses to insert native.newTextField (solved)

At the scene:create() section I have a field created&designed for fun&solution.

    local blaBla = native.newTextField (x, y, width, height)
    blaBla:addEventListener ("userInput", inputListener)
    blaBla.placeholder = "The Answer to the Ultimate Question of Life is ..."

Neither I try to sceneGroup:insert (blaBla) or not, this field is visible at the all previous scenes.
What’s wrong with it? All other objects that were inserted into the same particular sceneGroup are dissappearing properly.

The text field is not a display object, so AFAIK it is never inserted on your group, it just simulates it.

So, when te group is removed, the text field won’t appear among it’s children objects. You will have to remove it manually.

1 Like

@depilz, I was wondering how Corona/Solar2D SDK has a hard time keeping up when a scene is succeeded by another one. I thought, I get the picture, thanks to your answer… Absolutely all “expired” elements won’t be removed and erased from memory atomatically, I must shoot som’of’em manually. Magic! But it works. Maybee…

The textfield is a native object. There are other native objects too. It can be placed in displaygroup and will move together, but will appear on top.

Special care has to be taken on native objects, where you need to manually remove them. From the docs :

To remove a native text field from the display, use object:removeSelf().
2 Likes

Native display objects, including all of these (https://docs.coronalabs.com/api/library/native/index.html) aren’t a part of the OpenGL canvas and as such they can’t be added to groups.

You just need to manage all such things manually.

2 Likes

@yosu and @XeduR
I’ve just tried this method in scene:destroy () part:

blaBla:removeSelf()
blaBla = nil

PS. I tried this way:

inputFields = display.newGroup()
inputFields:insert (blaBla)

Later, in scene:destroy():

inputFields:removeSelf()
inputFields = nil

And, it appears on top again! Magic. Dark magic. Dark as I am.

PPS. Offtop question, by the way. What is the difference between sceneGroup:insert (blaBla) and anyGroup:insert (blaBla).

Do you have a sample code ? solar2d’s sample code “NativeDisplayObjects” has a good example. It removes the native objects nicely.

For me, I usually put all native objects into a table like this :

   table.insert( allNativeObjects, thisNativeObject)
   -- Later on.... remove them all recursively in scene:onHide
   for i=1,#allNativeObjects do
       display.remove(allNativeObjects[i])
   end

Excerpt from the sample code :

-- Cleanup function
local function cleanUp( event )

-- Remove existing labels
for i = labelGroup.numChildren,1,-1 do
	display.remove( labelGroup[i] )
	labelGroup[i] = nil
end
objectLabel.text = ""
currentObject = ""

-- Remove existing native objects
if ( textField ) then
	display.remove( textField )
	textField = nil
elseif ( textBox ) then
	display.remove( textBox )
	textBox = nil
elseif ( mapView ) then
	display.remove( mapView )
	mapView = nil
elseif ( webView ) then
	display.remove( webView )
	webView = nil
end
end
1 Like

@yosu, wow, that might be a little trickier than object:removeSelf().
Thank you.

PS. Checked. Works. At last!
Дякую.