michelperez
7 years agoVisitor
How to expose fields obtained inside screen to main thread for a SignIn component
Hi, I'm trying to create a SignIn component, but once I get username and password from the user in my component I can't "export" them back to the main thread. This is what I'm trying right now:
Now, in main.brs I have:
When I set field "password" and I try a `getField` after that I get `invalid`, also nothing is caught in the main thread. Basically what I want is a way to pass login data out of the component. Is this the better approach? What am I doing wrong?
Thanks!!
<component name = "SignInScene" extends = "Scene" >
<script type = "text/brightscript" >
<![CDATA[
sub init()
m.communicator = m.top.findNode("communicator")
m.communicator.addField("password", "roString", true)
...
end sub
sub onPasswordKeyboardBtnSelected(roEvent)
if roEvent.getData() = 0 then
if m.password <> "" and m.password <> invalid then
m.communicator.setField("password", m.password)
...
end if
end if
end sub
<children>
<Label id="communicator"/>
</children>
</component>
Now, in main.brs I have:
screen = CreateObject("roSGScreen")
m.port = [i]CreateObject[/i]("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("SignInScene")
screen.Show()
scene.findNode("communicator").observeField("password", m.port)
while (true)
msg = wait(0, m.port)
msgType = type(msg)
LogToConsole(msgType)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
end while
When I set field "password" and I try a `getField` after that I get `invalid`, also nothing is caught in the main thread. Basically what I want is a way to pass login data out of the component. Is this the better approach? What am I doing wrong?
Thanks!!