How to Access another file Label using a Brightscript?

独自空忆成欢 提交于 2019-12-02 08:35:08

问题


I'm trying to simple navigation. And I tried more than one way to open another screen.

  1. Hide/show concept (But It's working only single File).
  2. Using View Stack (But Still Not Working)
  3. Using tag and inside the tag to call another file. (But Its error has given Interface not a member of BrightScript Component)
  4. Using the same tag and inside the tag to call another file. (But It does not fetch the value from another file).

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

<?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>

Here the .brs file in the key event set to open another screen(click option key and open a new screen)

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

My second screen XML and brs both in single file File is

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.


回答1:


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.

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.

So you have two options:

1 - On your panelSet.brs instead of calling "m.top.ComponentController" change it for "m.top.getScene().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.

Doc



来源:https://stackoverflow.com/questions/57374718/how-to-access-another-file-label-using-a-brightscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!