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>

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?

I’m not trying to close the application.i just want close the dialog pop-up and focus will be on the previous screen.

“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”?

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

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

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

Hi jeswin,

i have tried your code, it’s not working.

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