How to create timer in roku.
Timer node is used to create timer objects or, more simply, timers, if you want any task to be executed after specific interval of time in roku then Timer Node is best you have as the prime functionality of timer is to fire/execute the tas after certain time interval has elapsed.For example, you could create Timer node to fire an event or execute code after specific interval of time.
The main objective of timer node is to generate an observable event after specific amount of time elapsed.
Fields of timer node has been explained below :
1 Control : It is of String type, this node is used to control the operation of timer node. It accepts two value i.e Start and Stop,to start the timer this is the syntax
m.timer.control = "start",
to stop the timer, this is the syntax : m.timer.control="stop"
2. Repeat : It is of boolean type, by default it is false, if you want your task to keep on executing after the specified time interval then do set this field to true which ll make timer node fires repeatedly, each time the specified duration field value elapses. If set to false, the Timer node only fires once.
3 Duration : It is of time type i.e it accepts time in milliseconds. Specifies the time in seconds before the Timer node fires after the control field value is set to start.
4. Fire : It is used to trigger timer.
You will get the better idea from below explained example, which will update the text string after every 10 Seconds.
<script type="text/brightscript" >
m.textChangeTimer = m.top.findNode("textChangeTimer") ' Here we have initialized timer object
m.textChangeTimer.control = "start" ' here we have started the timer.
m.text1 = "Please wait….."
m.text2 = “Fire the timer….."
m.label1 = m.top.FindNode("label1")
m.label1.text = m.text1
m.textChangeTimer.ObserveField("fire","changetext") ' Here we hav declared Observe field which will call method – changeText after 10 seconds.
m.label1.text = m.text2
width = "1280"
translation = "[0,500]"
horizAlign = "center"
vertAlign = "center"