TIMER
This element is not an actual data type but simply fires an event on a regular basis, when specified time has elapsed.
Attributes brief detailed show all inherited
Name | Description | Default | |||
---|---|---|---|---|---|
enabled | Enables or disables the timer | 'true' | |||
refresh_time_ms | interval between two timer events | 50 | |||
Events | |||||
elapsed | Fired when specified refresh_time_ms has elapsed, if the event is enabled |
See Attributes Common to All Elements.
Specific Attributes
Examples
Script Timer
The following code creates a timer launched by a button that calls a simple script (using an ACTION_TRIGGER) measuring elapsed time while it is displayed on screen. Once elapsed_time reaches 1000 ms, timer is stopped and a message box is displayed:
- <?xml version="1.0" encoding="utf-8" ?>
- <SKIN text_color="#ffffff" font_size="28" font_face="Arial">
- <!-- Creates a disabled timer -->
- <TIMER id="timer" enabled="false" refresh_time_ms="10"/>
- <!-- Elapsed parameter and alert action to be used by triggered script-->
- <PARAM id="elapsed" default="0" max="2000" exposed="true"/>
- <ACTION id="alert" type="DisplayMessageBox" message="button clicked 1 second ago" exposed="true"/>
- <!--script action trigger on timer event-->
- <ACTION_TRIGGER event_id="timer.elapsed" script="elapsed+=timer.refresh_time_ms; if(elapsed>=1000) {timer.enabled=0; alert(); elapsed=0;}" async="false"/>
- <!-- Ensures that the refresh attribute is exposed to script-->
- <EXPOSED_OBJECTS object_ids="timer.refresh_time_ms"/>
- <!-- Simple "click me" button to start the timer and text field that shows elapsed time-->
- <COLUMN margin="5">
- <TEXT value="Click Here">
- <INVISIBLE_PARAM_BUTTON id="button" width="100%" height="100%" param_id="timer.enabled"/>
- </TEXT>
- <PARAM_TEXT font_size="15" param_id="elapsed" content="button clicked {value} ms ago" width="200"/>
- </COLUMN>
- </SKIN>
