[英]How to use buttonSelected in Roku Scenegraph application
我正在使用“鍵盤”對話框進行用戶輸入。 我保留了兩個按鈕“確定”和“取消”。 但是在使用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
]]>
在這里,為對話框創建一個功能。 在對話框中寫入觀察字段,其用法如下例:第一個參數是“字段名稱” ,另一個參數是“功能名稱” 。
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
您是否檢查過事件中的buttonSelected
內部buttonSelected
;-)
使用m.top.dialog.buttonSelected
將返回索引值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.