如何在场景图xml中使用onkeyevent()关闭rosgscreen?

时间:2016-12-08 09:41:23

标签: roku brightscript

我在.main.brs中创建了ConfirmSignout.xml场景,以显示一个带有两个按钮的对话框弹出窗口。 如果我在onKeyevent中调用dismissSignoutdialog(),则必须关闭弹出窗口和rosgscreen并将焦点放在上一个屏幕上。但对我而言,如果我调用dismissSignoutdialog(),则ros​​gscreen不会被关闭。

任何人都可以帮助我。

Main.brs

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 个答案:

没有答案