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: 
georgejecook
Streaming Star

Any way to pass return value from extended component function?

I have Component BaseClass extends Group
it has a function SayHello as string

I then extend it with ExtendedClass extends BaseClass
it extends funciton SayHello as string

Is there any way for ExtendedClass to get the SayHello value returned from BaseClass?
George Cook
https://georgejecook.github.io/
https://linkedin.com/in/georgejecook/
Roku developers slack group (https://join.slack.com/t/rokudevelopers/shared_invite/zt-4vw7rg6v-NH46oY7hTktpRIBM_zGvwA) : georgejecook

Contact me on roku developer slack group, or via pm to discuss consultancy/work opportunities/rooibos unit testing framework
0 Kudos
3 REPLIES 3
joetesta
Roku Guru

Re: Any way to pass return value from extended component function?

Perhaps you can add two fields to the BaseClass, a boolean that signals BaseClass to run its SayHello function and the other field that receives the value returned by that function.  Then the ExtendedClass could make use of those fields to call and receive the BaseClass SayHello value.
aspiring
0 Kudos
joetesta
Roku Guru

Re: Any way to pass return value from extended component function?

in BaseClass.xml
<field id="runSayHello" type="boolean" alwaysNotify="true" onChange="onRunSayHello" />
<field id="sayHelloResponse" type="string" />


in BaseClass.brs
sub onRunSayHello()
  m.top.sayHelloResponse = SayHello()
end sub


in ExtendedClass.brs
sub getBaseSayHello()
  m.top.observeField("sayHelloResponse","gotResponse")
  m.top.runSayHello = true
end sub

sub gotResponse()
  print "Response: "; m.top.sayHelloResponse
end sub
aspiring
0 Kudos
georgejecook
Streaming Star

Re: Any way to pass return value from extended component function?

Thanks,

I use this strategy pattern extensively, in all languages. I was hoping that there'd be a provision for simple overriding; but more widely using deference, as you suggest, is just as good a solution.

Appreciate the code snippets! Thanks!
George Cook
https://georgejecook.github.io/
https://linkedin.com/in/georgejecook/
Roku developers slack group (https://join.slack.com/t/rokudevelopers/shared_invite/zt-4vw7rg6v-NH46oY7hTktpRIBM_zGvwA) : georgejecook

Contact me on roku developer slack group, or via pm to discuss consultancy/work opportunities/rooibos unit testing framework
0 Kudos