native.newTextBox not hiding on any build using removeSelf or display.remove()

Hi All,

What should be an easy piece of code that has worked before isn’t working now.

A button press which works fine (it seems!), prints to the console as below and then instructs the textbox to be removed…but doesn’t on the latest daily build, the current stable release in the simulator or iPad physical device.

Please can someone shed some light on this for me?

The referenced “Easier1” is a global variable defined in main.lua to hold text entries across all composer scenes.

local storyboard = require("composer"); local scene = storyboard.newScene(); local g=""; local txtEasier1=""; function scene:create() g = self.view; --main background local bg = display.newImage(g,"i/bgStep5.png",0,0,768,1024); -- control buttons --back local btn\_Back = display.newImage( g,"i/btnBack.png", -30, 400, 70, 70, true ) btn\_Back.width=70; btn\_Back.height=70; function btn\_Back:touch(event) if event.phase == "ended" then if txtEasier1 ~= nil then print("removing text") Easier1 = txtEasier1.text; txtEasier1:removeSelf(); txtEasier1=nil; end storyboard.gotoScene("step4", "slideRight",sceneTransition); end end btn\_Back:addEventListener("touch"); end

My code adds a new textbox on scene show:

function scene:show() txtEasier1 = native.newTextBox( 142, 287, 485, 376) txtEasier1.isEditable=true; txtEasier1.text=Easier1; native.setKeyboardFocus(txtEasier1); end

Many thanks

Chris

Anyone?

Your scope is a little off try this

function scene:create( event ) g = self.view; -- control buttons --back local btn\_Back = display.newRect( g, display.contentCenterX, display.contentCenterY, 100, 100 ) txtEasier1 = native.newTextBox( display.contentCenterX, display.contentCenterY-100, 300, 100) txtEasier1.isEditable=true; txtEasier1.text=Easier1; g:insert( txtEasier1 ) native.setKeyboardFocus(txtEasier1); function btn\_Back:touch(event) if event.phase == "ended" then if txtEasier1 ~= nil then Easier1 = txtEasier1.text; txtEasier1:removeSelf() txtEasier1=nil end composer.gotoScene("step4"); end end btn\_Back:addEventListener("touch"); end

Thanks for the suggestion.

The only problem I have with this is textboxes are native objects and appear above every thing else so when I create the scene and the textbox, it appears before the transition of the composer panel finishes and of course looks silly.

I would have thought of setting a empty txtEasier1 variable outside the composer functions would let other methods access the same native object regardless of scope? Like a class variable opposed to a function variable. Certainly the global’s I’m setting in main.lua are all accessible in any sub-view…

As a fall back option I will build a version that has no transitions and this solution will fix the issue. I’d still like to find a solution though that includes composer panel transitions and native objects (like I had before).

Any further thoughts would be greatly appreciated.

Hi @Milner99,

What kind of Composer transitions are you using? Movement/shift types or fadein/out types? Native text input objects can move along with groups, so that should be possible to accomplish. Fade transitions would present a tricky situation though…

Brent

Anyone?

Your scope is a little off try this

function scene:create( event ) g = self.view; -- control buttons --back local btn\_Back = display.newRect( g, display.contentCenterX, display.contentCenterY, 100, 100 ) txtEasier1 = native.newTextBox( display.contentCenterX, display.contentCenterY-100, 300, 100) txtEasier1.isEditable=true; txtEasier1.text=Easier1; g:insert( txtEasier1 ) native.setKeyboardFocus(txtEasier1); function btn\_Back:touch(event) if event.phase == "ended" then if txtEasier1 ~= nil then Easier1 = txtEasier1.text; txtEasier1:removeSelf() txtEasier1=nil end composer.gotoScene("step4"); end end btn\_Back:addEventListener("touch"); end

Thanks for the suggestion.

The only problem I have with this is textboxes are native objects and appear above every thing else so when I create the scene and the textbox, it appears before the transition of the composer panel finishes and of course looks silly.

I would have thought of setting a empty txtEasier1 variable outside the composer functions would let other methods access the same native object regardless of scope? Like a class variable opposed to a function variable. Certainly the global’s I’m setting in main.lua are all accessible in any sub-view…

As a fall back option I will build a version that has no transitions and this solution will fix the issue. I’d still like to find a solution though that includes composer panel transitions and native objects (like I had before).

Any further thoughts would be greatly appreciated.

Hi @Milner99,

What kind of Composer transitions are you using? Movement/shift types or fadein/out types? Native text input objects can move along with groups, so that should be possible to accomplish. Fade transitions would present a tricky situation though…

Brent