Extends Node

The Timer node class generates an observable event after a specified amount of time has elapsed.

Example

The following changes the text string on the display screen every five seconds as the Timer node generates a fire field observable event.

Timer Node Class Example

<?xml version="1.0" encoding="utf-8" ?>
 
<!--********** Copyright 2015 Roku Corp.  All Rights Reserved. **********-->
 
<component   name="timertest"   extends="Group" >
 
<script type="text/brightscript" >
<![CDATA[
 
sub init()
  m.testtimer = m.top.findNode("testTimer")
  m.testtimer.control = "start"
  m.defaulttext = "Wait for it, wait for it..."
  m.alternatetext = "Timer fired!!!"
 
  m.testtimerlabel = m.top.FindNode("testTimerLabel")
  m.testtimerlabel.text = m.defaulttext
  m.textchange = false
  m.testtimer.ObserveField("fire","changetext")
  m.top.setFocus(true)
end sub
 
sub changetext()
  if (m.textchange = false) then
    m.testtimerlabel.text = m.alternatetext
    m.textchange = true
   else
     m.testtimerlabel.text = m.defaulttext
     m.textchange = false
   end if
end sub
 
]]>
</script>
 
<children>
 
<Label
  id="testTimerLabel"
  width = "1280"
  translation = "[0,500]"
  horizAlign = "center"
  vertAlign = "center"
/>
 
<Timer
  id="testTimer"
  repeat="true"
  duration="5"
/>
 
</children>
 
</component>

Fields

FieldTypeDefaultAccess PermissionDescription
controlstringnoneREAD_WRITEUsed to control the operation of the Timer node. Recognized values include:
ValueEffect
noneNo effect
startStarts the Timer node operation
stopStops a running Timer node
repeatBooleanfalseREAD_WRITEIf set to true, the Timer node fires repeatedly, each time the specified duration field value elapses. If set to false, the Timer node only fires once until restarted
durationtime1READ_WRITESpecifies the time in seconds before the Timer node fires after the control field value is set to start. To specify time values down to millisecond granularity, use a float type (0.001 equals one millisecond)
fireEventN/AOBSERVE_ONLYTriggers observer callback functions when the Timer node fires. Please note that the timer observer callback executes on the render thread

Sample app

TimerExample is a sample app demonstrating Timer in action.