如何用海报图像替换infoLabel描述?

时间:2019-05-29 22:09:29

标签: brightscript

我需要转换如下代码,以便“ infoLabel”显示图片而不是文字。

此代码从字段ID为“ posteruri”而不是“ description”的XML字符串中读取

我有一个带有标签/说明的工作脚本示例。而我尝试转换为海报,这是行不通的。

我的尝试没有返回错误,但是除了空白矩形外,什么都没有显示。

<?xml version="1.0" encoding="utf-8" ?> 

<component name="categoryinfoPanel" extends="Panel" >

<interface>
   <field id="description" type="string" onChange="showdescription" /> 
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
  m.top.panelSize = "medium"
  m.top.focusable = true
  m.top.hasNextPanel = true

  m.infolabel = m.top.findNode("infoLabel")
end sub

sub showdescription()
  m.infolabel.text = m.top.description 
end sub

]]> 
</script>

<children>

<Rectangle
  id = "infoRectangle"
  translation = "[0,40]"
  height = "420"
  width = "520"
  color = "0x00000099" >

  <Label
    id = "infoLabel"
    translation = "[15,15]"
    height = "595"
    width = "510"
    wrap = "true"
    font = "font:MediumBoldSystemFont" />

</Rectangle>

</children>

</component>

我尝试过简单地替换字段ID,并用底部的Poster替换Label无效。

<?xml version="1.0" encoding="utf-8" ?> 

<component name="categoryinfoPoster" extends="Panel" >

<interface>
   <field id="posteruri" type="string" onChange="showdescription" /> 
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
  m.top.panelSize = "medium"
  m.top.focusable = true
  m.top.hasNextPanel = true

  m.infoposter= m.top.findNode("infoPoster")
end sub

sub showdescription()
  m.infoposter.uri = m.top.poster 
end sub

]]> 
</script>

<children>

<Rectangle
 id = "infoRectangle"
 translation = "[0,40]"
  height = "420"
  width = "520"
  color = "0x00000099" >

  <Label
    id = "infoPoster"
    translation = "[15,15]"
    height = "400"
    width = "510" />

</Rectangle>

</children>

</component>

当前文本显示在onChange上。我希望图像显示onChange

2 个答案:

答案 0 :(得分:0)

    <?xml version="1.0" encoding="utf-8" ?> 

<component name="categoryinfoPoster" extends="Panel" >

<interface>
   <field id="posteruri" type="string" onChange="showdescription" /> 
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
  m.top.panelSize = "medium"
  m.top.focusable = true
  m.top.hasNextPanel = true

  m.infoposter= m.top.findNode("infoPoster")
end sub

sub showdescription()
  m.infoposter.uri = m.top.poster 
end sub

]]> 
</script>

<children>

<Rectangle
 id = "infoRectangle"
 translation = "[0,40]"
  height = "420"
  width = "520"
  color = "0x00000099" >

  <Poster
    id = "infoPoster"
    translation = "[15,15]"
    height = "400"
    width = "510" />

</Rectangle>

</children>

</component>

您需要将“矩形”节点中的“标签”节点替换为“海报”节点。 看起来您做了所有的事情,除此之外。因此,您正在将“ uri”传递到“ label”节点,这就是为什么您没有看到图像的原因。 我还假设您因此而在调试器中遇到了一些错误。

答案 1 :(得分:0)

下面是对我有用的完整代码。感谢U.Mitic在PosterNode中捕获我的错误。并记住是否使用场景图模板。字段ID中,只有HDPosterUrl或SDPosterURL适用于海报。

''''      

<component name="categoryinfoPoster" extends="Panel" >

<interface>
   <field id="hdposterurl" type="string" onChange="showdescription" /> 
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
  m.top.panelSize = "medium"
  m.top.focusable = true
  m.top.hasNextPanel = true

  m.infoposter= m.top.findNode("infoPoster")
end sub

sub showdescription()
  m.infoposter.uri = m.top.hdposterurl
end sub

]]> 
</script>

<children>

<Rectangle
 id = "infoRectangle"
 translation = "[0,40]"
  height = "420"
  width = "520"
  color = "0x00000099" >

  <Poster
    id = "infoPoster"
    translation = "[15,15]"
    height = "400"
    width = "510" />

</Rectangle>

</children>

</component> 

''''