DEV Community

Uros Mitic
Uros Mitic

Posted on

2 1

How to define a function in component interface on Roku(BrightScript/SceneGraph)

If you have custom component named "doWhateverScreen" and you would like to print a string passed down from a different component named "HomeScene" using function in "doWhateverScreen" component interface, this is how you would do it.

First in your doWhateverScreen.xml file add:

    <interface>
        <function name="doWhateverMan" />
    </interface>
Enter fullscreen mode Exit fullscreen mode

Now in doWhateverScreen.brs file add your "doWhateverMan" function:

    Function doWhateverMan(param as String)
        print param
    End Function
Enter fullscreen mode Exit fullscreen mode

Great, so far so good!Let us continue.
In your HomeScene.xml add this custom created "doWhateverScreen" screen/component and in HomeScene.brs init() function add:

    m.doWhateverScreen= m.top.findNode("doWhateverScreen")
Enter fullscreen mode Exit fullscreen mode

We can now call a function named "doWhateverMan" from HomeScene.brs with:

    param = "Do Androids Dream of Electric Sheep?"
    m.doWhateverScreen.callFunc("doWhateverMan",param)
Enter fullscreen mode Exit fullscreen mode

That's it! Have a great day. :-D

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay