Search code examples
rokubrightscript

How to use Interface in brightscript for functions


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?


Solution

  • 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)