I want a function need to be called using interface-implementation model. I have read that roku has provision to have a function inside the interface portion in brightscript's document. So I tried but failed. Could anyone help me?
Asked
Active
Viewed 1,822 times
3
-
1Please add code you tried to launch. – Roman Podymov Jan 17 '18 at 11:41
-
Yes, this question needs more detail to be answerable. Suggest showing examples (in code) of what was tried. – Jess Bowers Jan 25 '18 at 20:46
-
In my case, there is a component in a.xml and it's script in a.brs. In script I have a method foo() in both the interface and implementation segments. Now I add a.brs in component b and trying to access foo() method and I got error – ganka Jan 26 '18 at 10:28
-
1@ganka ok, but can you post that actual code & error in your question (edit the question)? otherwise this question is not answerable. – Jess Bowers Feb 03 '18 at 13:56
-
U.Mitic hit the nail on the head. The params that are passed when you call your function are supposed to be wrapped inside of an associative array or an array. Here is more information on that. It makes the whole process rather tedious so I don't usually use these. https://sdkdocs.roku.com/display/sdkdoc/Handling+Application+Events#HandlingApplicationEvents-FunctionalFields – JSON Derulo May 04 '18 at 17:50
1 Answers
5
This is how you would implement a function inside an interface:
For example, create a custom screen named "audioPlayer" and in the audioPlayer.xml file add:
<interface>
<function name="doSomething" />
</interface>
In the audioPlayer.brs file declare "doSomething" function:
Function doSomething(param as String)
print param
End Function
Now in your HomeScene.xml add this custom created "audioPlayer" screen/component and in HomeScene.brs init() function add:
m.audioPlayer = m.top.findNode("audioPlayer")
You can call your doSomething() function from HomeSceene.brs with this peace of code:
param = "Do Androids Dream of Electric Sheep?"
m.audioPlayer.callFunc("doSomething",param)

U.Mitic
- 744
- 1
- 6
- 14
-
-
@U.mitic hello Sorry But I read your answer and your blog also But I face some issue on here `Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/components/ChannelList.brs(19) 019: m.WisePanel.callFunc("doSomething",param)` – Nikunj Chaklasiya Aug 06 '19 at 06:17
-
my another try to same issue here `Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/components/PanelSet.brs(12) 012: m.KeyboardDialogExample.callFunc("doSomething",param)` to use different two file. – Nikunj Chaklasiya Aug 06 '19 at 06:19
-
@NikunjChaklasiya - To me it looks like You did not add "doSomething" function to the m.WisePanel interface in .xml file of m.WisePanel. – U.Mitic Aug 06 '19 at 16:56
-
Here I use two components one is wisepanel and another is keyboarddialog. Wisepanel dedicates to first screen and keyboarddialog dedicate second screen. So I interface tag write in second screen it keyboarddialog and write function on brs file. And dosomthing call in wisepanel. Is it correct? – Nikunj Chaklasiya Aug 06 '19 at 18:37
-
1In my case, I am not being able to access the component by findNode function. It prints out as an invalid. – AEB Jun 04 '20 at 08:45
-
You probably did not append it to the parent node. findNode function will not work if the node you are trying to find is not a child to some node. – U.Mitic Jun 04 '20 at 09:13
-