Interfaces are a way of communicating between components, a way to pass data between components.
A component can write to an interface field, or read from an interface field, or both.
One use would be for one custom component to set some property of another custom component. To do this, one component writes a value to the interface field of the other component, which the other component then reads when it is notified (using an event observer) that the value of the interface field has changed.
Let's say you have a component (ComponentA) that contains a Label component, and you want to set its text from another component (ComponentB).
In ComponentA.xml, you'd have a Label whose text you want to change defined inside the <children> element:
<Label id="idLabel" />
In ComponentA.xml, you'd define an interface field along with the name of the event observer function that will be executed when the field value changes:
<interface>
<field id="labelText" type="string" onChange="onLabelTextChange" />
</interface>
In ComponentA.brs, you'd set up a reference to the Label field:
sub init()
m.label = m.top.findNode("idLabel")
end sub
In ComponentA.brs, you'd define an event observer that gets executed when the value of labelText changes, by referencing the interface field:
sub onLabelTextChange()
m.label.text = m.top.labelText
end sub
To change the text of ComponentA's label from ComponentB, you'd set up a reference to ComponentA in ComponentB.brs:
sub init()
m.componentA = m.top.findNode("ComponentA")
end sub
Then set the value of the interface field somewhere in ComponentB.brs:
m.componentA.labelText = "Hello, World!"