【发布时间】:2020-09-08 05:51:39
【问题描述】:
我正在尝试在按钮单击的两个屏幕之间来回导航。我有以下代码。
TestScreen1.xml
<?xml version="1.0" encoding="utf-8" ?>
<component name="TestScreen1" extends="Scene">
<children>
<Label id="myLabelScreen1"
width="1280"
height="720"
horizAlign="center"
vertAlign="top"
translation="[0, 30]"
/>
<Poster
id="screenAPosterScreen1"
translation="[470, 300]"
width="0.0"
height="0.0"
visible="true">
</Poster>
<Button
id="screen1Button"
text="Go to Screen 2"
width="100"
height ="70"
translation="[470, 450]"
showFocusFootprint="true"
/>
</children>
<!-- BrightScript Portion -->
<script type="text/brightscript" uri="TestScreen1.brs" />
<script type="text/brightscript" uri="pkg:/source/Main.brs" />
<!-- End of BrightScript Portion -->
</component>
TestScreen1.brs
function init()
m.top.setFocus(true)
m.myLabel = m.top.findNode("myLabelScreen1")
m.screenAPoster = m.top.findNode("screenAPosterScreen1")
m.Button = m.top.findNode("screen1Button")
m.Button.observeField("buttonSelected", "onButton1Press")
m.Button.setFocus(true)
jsonData = ParseJson(m.global.mystuff)
m.myLabel.text = jsonData.screens.a.title
m.screenAPoster.uri = jsonData.screens.a.logo
'Set the font size
m.myLabel.font.size = 92
'Set the color to light blue
m.myLabel.color = "0x72D7EEFF"
end function
现在TestScreen2.xml
<?xml version="1.0" encoding="utf-8" ?>
<component name="TestScreen2" extends="Scene">
<children>
<Label id="myLabelScreen2"
width="1280"
height="720"
horizAlign="center"
vertAlign="top"
translation="[0, 30]"
/>
<Poster
id="screenAPosterScreen2"
translation="[470, 300]"
width="0.0"
height="0.0"
visible="true">
</Poster>
<Button
id="screen2Button"
text="Go to Screen 1"
width="100"
height ="70"
translation="[470, 450]"
showFocusFootprint="true"
/>
</children>
<!-- BrightScript Portion -->
<script type="text/brightscript" uri="TestScreen2.brs" />
<script type="text/brightscript" uri="pkg:/source/Main.brs" />
<!-- End of BrightScript Portion -->
</component>
TestScreen2.brs
function init()
m.top.setFocus(true)
m.top.backgroundColor = "#FF0000"
m.myLabel = m.top.findNode("myLabelScreen2")
m.screenAPoster = m.top.findNode("screenAPosterScreen2")
m.Button = m.top.findNode("screen2Button")
m.Button.observeField("buttonSelected", "onButton2Press")
m.Button.setFocus(true)
jsonData = ParseJson(m.global.mystuff)
m.myLabel.text = jsonData.screens.b.title
m.screenAPoster.uri = jsonData.screens.b.logo
'Set the font size
m.myLabel.font.size = 92
'Set the color to light blue
m.myLabel.color = "0x72D7EEFF"
end function
Main.brs 文件
sub Main()
print "in showChannelSGScreen"
'Indicate this is a Roku SceneGraph application'
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("TestScreen1")
m.global = screen.getGlobalNode()
m.global.AddField("mystuff", "string", false)
port = CreateObject("roMessagePort")
request = CreateObject("roUrlTransfer")
request.AddHeader("secret-key", "$2b$10$uFTmoV/NUudBt3K/t8h9H.c08SIwq29I9RiZskcr5k.tU8lvpwfJ2")
request.AddHeader("Accept", "application/json")
request.AddHeader("Content-Type", "application/json")
request.EnablePeerVerification(false)
request.EnableHostVerification(false)
request.RetainBodyOnError(true)
request.SetCertificatesFile("common:/certs/ca-bundle.crt")
request.InitClientCertificates()
request.SetMessagePort(port)
request.SetURL("https://api.jsonbin.io/b/5e7e4017862c46101abf301f")
response = ParseJson(request.GetToString())
m.global.mystuff = request.GetToString()
screen.show()
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
end while
end sub
sub onButton1Press(event as object)
print "go to screen2"
'how to navigate to screen2
end sub
sub onButton2Press(event as object)
print "go to screen2"
'how to navigate to screen1
end sub
如何在两个屏幕之间来回导航,单击 screen1Button 转到屏幕 2,反之亦然在两个屏幕之间导航?
【问题讨论】:
标签: roku brightscript