如何使用按钮在Roku Scenegraph应用程序中选择

0 scenegraph roku

我正在使用“键盘”对话框进行用户输入。我保留了两个按钮“确定”和“取消”。但是在使用buttonSelected它的同时使用observeField调用了两个按钮。现在,有人可以告诉我如何buttonSelected在单击“确定”和“取消”的一个按钮时使用索引进行操作

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

  example = m.top.findNode("instructLabel")

  examplerect = example.boundingRect()
  centerx = (1280 - examplerect.width) / 2
  centery = (720 - examplerect.height) / 2
  example.translation = [ centerx, centery ]

  m.top.setFocus(true)
end sub

sub showdialog()
  keyboarddialog = createObject("roSGNode", "KeyboardDialog")
  keyboarddialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
  keyboarddialog.title = "Example Keyboard Dialog"

  keyboarddialog.buttons=["OK","CANCEL"]
  keyboarddialog.optionsDialog=true

  m.top.dialog = keyboarddialog
  print "hello"
 KeyboardDialog.observeField("buttonSelected","onKeyPress")
' KeyboardDialog.observeField("buttonSelected","onKeyPressCancel")
 print "world"
end sub




function onKeyPress()
    print "m.value:::>>"m.top.dialog.text
end Function
function onKeyPressCancel()

    print "Screen should close"
end Function

function onKeyEvent(key as String, press as Boolean) as Boolean
  if press then
    if key = "OK"
      showdialog()

      return true
    end if

    end if


  return false
end function



]]>
Run Code Online (Sandbox Code Playgroud)

Nik*_*iya 6

在这里,为对话框创建一个功能。在对话框中,写入观察字段的用法如下例:第一个参数是“字段名称”,另一个参数是“功能名称”

m.top.dialog.observeField("buttonSelected","onVerifyURL")

在功能下方是观察字段第二参数“ onVerifyURL”的要点

sub onVerifyURL()

 if m.top.dialog.buttonSelected = 0

       print "ok button pressed" 'O is called first
       'function call for OK

 else if m.top.dialog.buttonSelected = 1  

       print "cancel button pressed" '1 is called second
       'm.top.dialog.visible = false  
       'm.top.dialog.close = true
       'function call for Cancel

 else
       print "nothing press" ' this is not required for code just write for an understanding

 end if

end sub
Run Code Online (Sandbox Code Playgroud)