如何使用Brightscript访问另一个文件标签? [英] How to Access another file Label using a Brightscript?
问题描述
我正在尝试简单的导航.而且我尝试了多种方法来打开另一个屏幕.
I'm trying to simple navigation. And I tried more than one way to open another screen.
- 隐藏/显示概念(但仅适用于单个文件).
- 使用视图堆栈(但仍无法正常工作)
- 使用标签和标签内部调用另一个文件. (但是它的错误导致Interface不是BrightScript Component的成员)
- 在标签内使用相同的标签来调用另一个文件. (但是它不会从另一个文件中获取值).
在这里我的第一个文件在第一屏幕"中编写代码
Here My First File Write a code to First Screen
Main.brs
screen = CreateObject("roSGScreen") 'one Application only once roSGScreen
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("WisePanel") 'Here the First screen component name
screen.show()
PanelSet.xml
PanelSet.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="WisePanel" extends="Scene">
<script type="text/brightscript" uri="pkg:/components/PanelSet.brs" />
<Group id="FirstScreen" >
<Label
id = "lbfirstscreen"
font="font:LargeBoldSystemFont"
text = "This is the first Screen"
translation = "[200,250]" />
</Group>
</component>
在键事件集中设置.brs文件以打开另一个屏幕(单击选项键并打开一个新屏幕)
Here the .brs file in the key event set to open another screen(click option key and open a new screen)
PanelSet.brs
PanelSet.brs
sub init()
m.FirstScreenLabel = m.top.findNode("lbfirstscreen")
end sub
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if key="options" then
' Here the write a Logic
keyboard= CreateObject("roSGNode", "KeyboardDialog")
?"call keyevent Fucntion"
'here show function to give a error
m.top.ComponentController.CallFunc("show", {
view: keyboard
})
end if
end if
end function
我在单个文件File中的第二个屏幕XML和brs都是
My second screen XML and brs both in single file File is
keyboarddialogscene.xml
keyboarddialogscene.xml
<?xml version = "1.0" encoding = "utf-8" ?>
<component name = "KeyboardDialog" extends = "Group" >
<script type = "text/brightscript" >
<![CDATA[
sub init()
m.SecondScreenLabel = m.top.findNode("lblsecondscreen")
end sub
]]>
</script>
<children >
<Group id="SecondScreen" >
<Label
id = "lblsecondscreen"
font="font:LargeBoldSystemFont"
text = "This is the second Screen"
translation = "[200,250]" />
</Group>
</children>
</component>
我尝试单击远程选项"键,然后在第二个屏幕上显示一个标签",任何人都知道该问题.
I try to Click in Remote Option key then I display a Label on second screen File anyone knows the issue.
推荐答案
我使用了您的代码,可以使它正常工作,但是我进行了一些调整.
I used your code, I was able to make it work, however, I made some adjustments.
我认为您目前使用的代码问题是一个范围" 问题,请允许我解释一下.
I think your issue with the code just as you have it right now, is a "scope" issue, let me explain a little bit.
您试图在panelset.brs文件中调用"m.top.ComponentController",但"ComponentController"不是面板集组件上的字段,在该范围内,您只能访问面板集界面上的字段.
You are trying to call "m.top.ComponentController" within you panelset.brs file but "ComponentController" is not a field on the panelset component, in that scope you can only access the fields on the panelset interface.
因此,您有两种选择:
1-在您的panelSet.brs上,而不是调用"m.top.ComponentController",将其更改为"m.top.getScene().ComponentController".
1 - On your panelSet.brs instead of calling "m.top.ComponentController" change it for "m.top.getScene().ComponentController".
2-在您的wisePanel.xml上创建一个字段,在创建WisePanel组件的那个字段中添加一个侦听器,在该范围内,您将可以m.top.componentController.
2 - Create a field within your on your wisePanel.xml, add a listener to that field where you create the WisePanel component, in that scope, you'll be able to m.top.componentController.
Note: I used the setup_and_helloworld link example of the Roku Dev with your files.
这篇关于如何使用Brightscript访问另一个文件标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!