Home > Articles

  • Print
  • + Share This

Timers

Timers allow programmatic reaction to user idle time. A timer starts counting down when a user enters a card. When the timer counts down to zero, an event handler, associated with the timer, is activated. Timers can be interrupted by execution of a task such as go, prev or refresh. Timers are declared only within cards, and only one timer element (<timer/>) is allowed per card. The timeout value is specified by setting the value attribute to a number in tenths of a second. For example, value = "100" creates a 10-second timer. The name attribute can be used to specify a variable that will contain the timer's value (as in 0 upon timeout). For example, <timer name="splashTimer" value="50"/> declares a 5-second timer with a variable named splashTimer that will contain the countdown time.

Timeout events are handled using the onevent element (with the type set to ontimer) or the shortcut ontimer attribute. A timeout event is specified at the card or deck level. When set at the deck level, the timer applies to all cards in the deck that do not declare their own timer event handler.

Figure 1 illustrates the use of a timer to control a splash screen (the first screen), which displays for 5 seconds before transferring control to the second screen (unless the user explicitly selects Categories in this time). Note that the timer element must be located before any do elements but is placed after the onevent handlers.

<wml>
  <!--First card is splash screen--> 
  <card>
    <onevent type="ontimer">
      <go href="#MainCategories"/>
    </onevent>
    <timer name="splashTimer" value="50"/>
    <do type="accept" label="Categories">
      <go href="#MainCategories"/>
    </do>
    <p align="center">
      . . .
    </p>
  </card>

  <!--Second card displays categories--> 
  <card id="MainCategories">
    <p mode="nowrap">
      . . .
    </p>
  </card>
</wml>

Figure 1 A timed splash screen

The onevent handler in Figure 1 can be replaced with a shortcut card attribute, as in this code:

.
.
<card ontimer="#MainCategories">
  <timer name="splashTimer" value="50"/>
.
.
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.