Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
veerareddya
Visitor

How to close rosgscreen using onkeyevent() in scene graph xml ?

I have created ConfirmSignout.xml scene in. main.brs to show some dialog pop-up with two buttons. If I call dismissSignoutdialog() in onKeyevent, pop-up and rosgscreen has to close and focus will be on the previous screen. But for me if I call dismissSignoutdialog(), rosgscreen is not getting closed.[/font]
Main.brs.[/font][/color]
sub ConfirmSignOUT() As Object
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("ConfirmSignout")
    screen.show()
    while(true)
        msg = wait(0, m.port)
        msgType = type(msg)
        if msgType = "roSGScreenEvent"
          if msg.isScreenClosed() then
            return -1
            exit while
          end if
        end if
    end while
End sub

ConfirmSignout.xml
<component name = "ConfirmSignout" extends = "Scene" >
  <script type = "text/brightscript" >
    <![CDATA[
     sub init()
        m.top.backgroundURI ="pkg:/images/rsgde_bg_hd.jpg"
        dialog = createObject("roSGNode", "Dialog")
        'dialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
        dialog.optionsDialog = false
        dialog.title = "Alert"
        dialog.message = "Are you sure you want to Signout?"
        dialog.buttons=["No","Yes"]
        dialog.visible = true
        m.top.dialog = dialog
    end sub

    sub dismissSignoutdialog()
        m.top.dialog.close = true
    end sub

    function onKeyEvent(key as String, press as Boolean) as Boolean
        button_val = m.top.dialog.buttonSelected
        if not press then
            if key = "OK"
                if(button_val = 0)
                    dismissSignoutdialog()
                    return true
                else if (button_val = 1)    
                    print "m.top";m.top
                    'return true
                end if  
            end if
        end if
      'return false
    end function

    ]]>

  </script>
  <children >

    <Label
      id = "SignoutLable" />

  </children>

</component>
0 Kudos
8 REPLIES 8
belltown
Roku Guru

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

Are you trying to close the whole Scene Graph application and exit back to the Home screen, or close something else and keep the application running?
0 Kudos
veerareddya
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

I'm not trying to close the application.i just want close the dialog pop-up and focus will be on the previous screen.
0 Kudos
belltown
Roku Guru

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

"veerareddya" wrote:
I'm not trying to close the application.i just want close the dialog pop-up and focus will be on the previous screen.

Where is this "previous screen"?
0 Kudos
veerareddya
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

I am using screen.Close() method in the while loop. is this correct way i am doing ? and how to access the data from brs to xml scene??
ex: m.global.setField("tempmessage", "Are you sure you want to Signout?") I want access  this "tempmessage"  value in the ConfirmSignout.xml.
could you please help me on this..

Main.brs

sub ConfirmSignOUT() As Object
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    m.global = screen.getGlobalNode()
    m.global.id="GlobalNode"
    m.global.setField("tempmessage", "Are you sure you want to Signout?")
    scene = screen.CreateScene("ConfirmSignout")
    screen.show()
    while(true)
        msg = wait(1000, m.port)
        if(scene.visible = false)
          screen.Close()
          return Invalid
        endif
    end while    
End sub

ConfirmSignout.xml

<component name = "ConfirmSignout" extends = "Scene" >
 
  <script type = "text/brightscript" >
 
    <![CDATA[
 
    sub init()
print "m.top";m.global.id
m.top.backgroundURI ="pkg:/images/rsgde_bg_hd.jpg"
dialog = createObject("roSGNode", "Dialog")
dialog.optionsDialog = false
dialog.title = "Alert"
dialog.message = m.global.tempmessage
dialog.buttons=["No","Yes"]
dialog.visible = true
m.top.dialog = dialog
end sub

sub dismissSignoutdialog()
m.top.dialog.close = true
m.top.visible = false
m.top.backExitsScene = false
end sub

    function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
button_val = m.top.dialog.buttonSelected
if not press then
if key = "OK"
if(button_val = 0)
dismissSignoutdialog()
return true
else if (button_val = 1)
print "m.top";m.top
'return true
end if
else if key = "back"
m.top.backExitsScene = false
end if
end if
      'return false
    end function
  
    ]]>
 
  </script>
 
  <children >
 
    <Label
      id = "SignoutLable" />
 
  </children>
 
</component>
0 Kudos
Anish1
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

So Veerareddya have you found the solution of your code......as i have been through the same issue....if so then please share it with us....i will be highly obliged.....THANKS
0 Kudos
jeswin
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

Follow the Code below
Main.brs
 screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  m.global =screen.getGlobalNode()
  m.global.id="GlobalNode"
  m.global.addFields({tempmessage:"Are you sure you want to Signout?"})
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("ConfirmSignout")
  screen.show()


ConfirmSignout.xml

sub init()
 print m.global.tempmessage
 m.top.backgroundURI ="pkg:/images/rsgde_bg_hd.jpg"
  dialog = createObject("roSGNode", "Dialog")
  dialog.optionsDialog = false
  dialog.title = "Alert"
  dialog.message = m.global.tempmessage
  dialog.buttons=["No","Yes"]
  dialog.visible = true
  m.top.dialog = dialog
end sub


You can see the tempmessage. Now you can use it in your dialog
Note: You cannot go back to main.brs once you create the scene
0 Kudos
veerareddya
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

Hi jeswin,

i have tried your code, it's not working. 
0 Kudos
veerareddya
Visitor

Re: How to close rosgscreen using onkeyevent() in scene graph xml ?

Hi Anish,

Yes, i have a solution,

Main.brs

    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("exitpopup")
    screen.show()
    scene.setField("tempmessage","Are you sure you want to exit YuppTV?")

xml code

<interface>
      <field id = "tempmessage" type = "String"  />
</interface>
   
  <script type = "text/brightscript" >
 
    <![CDATA[
 
    sub init()
m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
m.top.bak_press = "0"
m.top.blocker = 0
m.top.ObserveField("tempmessage", "Exitpopupdialog")
    end sub
 
    sub Exitpopupdialog()
dialog = createObject("roSGNode", "Dialog")
'dialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
dialog.optionsDialog = false
dialog.title = "Exit Application"
dialog.message = m.top.tempmessage
dialog.buttongroup.buttons =["Continue watching","Exit app"]
dialog.focusButton = 0
dialog.visible = true
m.top.dialog = dialog
m.top.setFocus(true)
m.top.dialog.ObserveField("buttonSelected","ButtonPressed")
end sub


try this it will work for sure
0 Kudos