Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
fry19
Binge Watcher

fieldToInterp for a top level component

I am trying to extend the Poster component this way:

 

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

<component name="PosterWithFadeIn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" extends="Poster" xsi:noNamespaceSchemaLocation="http://rokudev.roku.com/rokudev/schema/RokuSceneGraph.xsd">

  <children>
    <Animation
      id = "fadeIn"
      duration = "1"
      easeFunction = "linear" >

      <FloatFieldInterpolator
        key = "[ 0.0, 1.0 ]"
        keyValue = "[ 0.0, 1.0 ]"
        control="start"
        fieldToInterp = "????.opacity" />

    </Animation>
  </children>

</component>

The issue is that I have never seen any example that refers to the "main" component in an animation "fieldToInterp" attribute.

 

What shall I use? I tried "opacity", ".opacity", "m.top.opacity" and nothing works...

 

Thanks

0 Kudos
6 REPLIES 6
speechles
Roku Guru

Re: fieldToInterp for a top level component

<component name="PosterWithFadeIn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" extends="Poster" xsi:noNamespaceSchemaLocation="http://rokudev.roku.com/rokudev/schema/RokuSceneGraph.xsd">

  <children>

<Poster id="myPoster" loadheight="250" loadwidth="400" width="400" height="250" uri="" opacity="0.0" />
<Animation id = "fadeIn" duration = "1" easeFunction = "linear" > <FloatFieldInterpolator key = "[ 0.0, 1.0 ]" keyValue = "[ 0.0, 1.0 ]" fieldToInterp = "myPoster.opacity" /> </Animation> </children> </component>

 


...

the in brs:

m.poster = m.top.findnode("MyPoster")
m.animation = m.top.findnode("fadeIn")
m.poster.uri = < uri >

then during times when you want the animation and the poster to show use this:
m.animation.control = "stop"
m.animation.control = "start"

stop it always before you start it. you can only start a stopped task.

0 Kudos
fry19
Binge Watcher

Re: fieldToInterp for a top level component

@speechlesUnfortunately this does not answer the question I am asking. The top component is already a Poster (<component ... extends="Poster"...>).

 

In Brightscript I can simply access the "opacity" of the component by writing "m.top.opacity" and I want to access this very field in the animation. Not create another poster inside a Poster component.

 

The solution you propose also has the issue that if you write <PosterWithFadeIn uri="xxxx"/> the attribute uri is applied to the main component, not the one you define inside (and that is true for every single attribute...). This is why I am extending from Poster...

 

The question is to access the opacity field of the main component (or any other field for that matter) via the fieldToInterp attribute in the animation.

 

0 Kudos
speechles
Roku Guru

Re: fieldToInterp for a top level component

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

<component name="PosterWithFadeIn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" extends="Poster" xsi:noNamespaceSchemaLocation="http://rokudev.roku.com/rokudev/schema/RokuSceneGraph.xsd">

  <interface>
<field id="height" type="integer" value="0" alwaysNotify="true" onChange="OnChange" />
<field id="width" type="integer" value="0" alwaysNotify="true" onChange="OnChange" />
<field id="uri" type="integer" value="0" alwaysNotify="true" onChange="OnChange" />
<field id="opacity" type="float" value="1.0" alwaysNotify="true" onChange="OnChange" />
<field id="translation" type="array" value="[0, 0]" alwaysNotify="true" onChange="OnChange" />
</interface> <children> <Poster id="idPoster" /> <Animation id = "fadeIn" duration = "1" easeFunction = "linear" > <FloatFieldInterpolator key = "[ 0.0, 1.0 ]" keyValue = "[ 0.0, 1.0 ]" control="start" fieldToInterp = "idPoster.opacity" /> </Animation> </children> </component>

 

Then in the BRS:

 

Function OnChange()
    m.poster = m.top.findnode("idPoster")
    m.poster.height = m.top.height
    m.poster.width = m.top.width
    m.poster.opacity = m.top.opacity
    m.poster.uri = m.top.uri
m.poster.translation = m.top.translation End Function

 

0 Kudos
fry19
Binge Watcher

Re: fieldToInterp for a top level component

@speechlesThank you for your answers. I understand what you are trying to achieve and I agree with you that what you propose will work.

 

But it is still not answering the question I am asking. The field of the top level component is accessible in Brightscript via "m.top.opacity".

 

My question is: how do I access it from the Animation / fieldToInterp attribute.

 

And maybe at the end of the day, the answer is that it is not possible. But this is the question I am asking. If it is not possible, then yes there are workarounds (like what you suggest, or implementing the interpolation via a timer which is what I did...), but I am interested to know if it is possible at all and if yes, how.

0 Kudos
T0
Channel Surfer

Re: fieldToInterp for a top level component

In your component's init() function, set the id to some value, e.g.

sub init()
    m.top.id = "fadingPoster"
end sub

 

then set 

fieldToInterp = "fadingPoster.opacity"

 

0 Kudos
T0
Channel Surfer

Re: fieldToInterp for a top level component

Actually, no, that doesn't work. You can set the id of the component to be animated in brightscript to have it match the interpolator's fieldToInterp value, but it only works if the component is a child. The animation code must do a search of the top level component's children, but ignores the top level component itself.

Your best bet is to make the top level component a Group and replicate all the Poster fields you need.

Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.