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: 
rsromeo
Channel Surfer

Dialog and Closing App

Hi, just getting started with SG, I'm old school SDK trying to catch up.  I'm trying to launch a dialog and when user clicks OK, it ends the app.  I was trying to use the "dialog example" from Roku.
So what I do is call the below sub which displays the dialog shown in XML file below.  My problem is once user clicks OK, I want to close the app.  Right now, when I click OK, nothing happens because its doing nothing but returning Boolean value.  I'm not sure what I need to call at this point to kill the app.  I tried a roUrlTransfer call but it errors out on the SetUrl property ("http://localhost:8060/keypress/Home").  I assume this type of call won't work in the onKeyEvent so do I need to return focus somehow to the screen so I can close it?
Any help would be appreciated.

sub showChannelSGScreen()
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("DialogExample")
  screen.show()
  while(true)
    msg = wait(0, m.port)
    msgType = type(msg)
    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed()
      end if
    end if
  end while
end sub

XML FILE
<component name = "DialogExample" extends = "Scene" >
  <script type = "text/brightscript" >

    <![CDATA[

sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
      m.top.setFocus(true)
      showdialog()
end sub

    sub showdialog()
      dialog = createObject("roSGNode", "Dialog")
      dialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
      dialog.title = "My title"
      dialog.optionsDialog = true
      dialog.message = "Press * To Dismiss"
      m.top.dialog = dialog
      m.top.setFocus(true)
    end sub

function onKeyEvent(key as String, press as Boolean) as Boolean
  if press then
    if (key = "OK") then
    return true
    end if
end if
return false
end function
    ]]>
  </script>

</component>
0 Kudos
3 REPLIES 3
tim_beynart
Channel Surfer

Re: Dialog and Closing App

You need to tell the source/main.brs loop to exit, here's some crude and untested code that might do the trick

m.scene.findNode("myExitDialog").observeField("pleaseExitNow",m.port)
while true
  msg = wait(0, m.port)
  if type(msg) = "roSGNodeEvent"
if msg.getField() = "pleaseExitNow"
'close the loop, kill the app
  return
end if
  end if
end while
0 Kudos
rsromeo
Channel Surfer

Re: Dialog and Closing App

Thanks, will give it a try but I guess I have to add the node to the diaglogexample.xml file?  How do you do that?
0 Kudos
ramim94
Visitor

Re: Dialog and Closing App

Was anyone able to accomplish this?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.