[Resolved] Scene problem & advice

Hello

I got a serious problem and I really need some help. Because it’s make me crazy :frowning:

My application use the tabbar widget and storyboard to change scenes. This works good.

[code]-- require controller module
local storyboard = require “storyboard”
local widget = require “widget”

– load first screen
storyboard.gotoScene( “scene1” )

local function onOnePress( event )

storyboard.gotoScene( “scene1”, “fade”, 0 )

return true
end
local function onTwoPress( event )

storyboard.gotoScene( “scene2”, “fade”, 0 )

return true
end

local tabButtons = {
{
label=“Scene1”,
up=“icon1.png”,
down=“icon1-down.png”,
width=32, height=32,
onPress=onOnePress,
selected=true
},
{
label=“Scene2”,
up=“icon2.png”,
down=“icon2-down.png”,
width=32, height=32,
onPress=onTwoPress
},
}

– create the actual tabBar widget
local tabBar = widget.newTabBar{
top = display.contentHeight - 50,
buttons = tabButtons
}[/code]

The code works fine, but the problem is that in scene 2 there are nativeTextFields.

Problem:
1, Start app, scene 1 is load and scene 1 is on the screen.
2, User touched the scene 2 tabbar icon. --> Scene 2 is on the screen.
3, User touched back to scene 1 on the scene 1 tabbar icon. --> Scene 1 is on the screen.
4. Scene 1 is on the screen + nativeTextFields from scene 2 is on the screen!

The nativeTextFields must not be visible on scene 1… but how do I fix this? The must be removed/hide…

I build a test function in scene 2. And this function works! :smiley: When the user touched the test image the nativeTextFields are not showed on the screen of scene 1:)

But how can I add this or a better function to the main.lua file in the tabbar?

function zero() textfield.alpha = 0 end

image = display.newImage( "bg.jpg" ) screenGroup:insert( image ) image.touch = onSceneTouch

[code]
local function onSceneTouch( self, event )
if event.phase == “began” then

zero()
storyboard.gotoScene( “scene1”, “fade”, 0 )

return true
end
end[/code]

I think I’m on the right way, but need some help to make this work better :slight_smile:

Thanks. [import]uid: 150924 topic_id: 29368 reply_id: 329368[/import]

Native text fields are not display objects and cannot be put into display groups. Storyboard and Director are both based around the idea that they will manage anything that’s in a display group for you since they can move the on and off the screen.

Since you can’t put native text fields into a group, you have to manually hide/remove them.

In scene2’s exitScene() event handler, you can either manually remove the text fields, or you could set their .isVisible property to false to hide them and then in the destroyScene() event, remove them if you don’t want to recreate them every time you enter the scene.

Since storyboard wants to keep your scenes in memory for fast switching, I would either:

in createScene()
… create the objects and set their visibility to false

in enterScene()
… set their visibility to true

in exitScene()
… set their visibility to false

in destroyScene()
… remove the objects.

or if you want the simplest thing:

in enterScene()
… create the text fields

in exitScene
… remove the text fields

The later is more Director like, the former more storyboard’ish but both will work [import]uid: 19626 topic_id: 29368 reply_id: 118051[/import]

@ robmiracle, thank you! It’s works :slight_smile: Good start of the weekend:)

Yes I know about the nativeTextFields and groups don’t work together. The clear information you give me about the Storyboard is very good. Because now I understand it much better!

One more question about the nativeTextFields, i’m port my application from the Director Class to the Storyboard API.

The nativeTextFields are working on a local function fieldHandler.
This function, save the text input to a .txt file. And and limits the max characters to 6. And update the text in scene 1. When the user loads scene 1 again.

Right now, the text in scene 1 will be only updated if the application is re-start. But it must be updated and displayed in scene 1 when the user touched the tabbar icon for scene 1.

textfieldOne:addEventListener("userInput", fieldHandler) textfieldOne.text = loadFile ("one.txt")
For the update to work, where do I have to put this code? In scene 2, scene 1 or the main.lua file?

Runtime:addEventListener( "system", onSystemEvent )

and this one?

local function onSystemEvent () if textfieldOne \> textfieldOne.text then textfieldOne.text = saveFile("one.txt")

Alwin [import]uid: 150924 topic_id: 29368 reply_id: 118079[/import]

Fixed the problem :slight_smile:

The nativeTextFields in

scene:enterScene

And remove them here

scene:exitScene( event )

Somethings it’s hard to think simple… :slight_smile:

edit , nativeTextFields must be the display.newText’s [import]uid: 150924 topic_id: 29368 reply_id: 118281[/import]