Set up Timers

You can use the timer technical object with script APIs to initiate timing events in view time.

Context

By setting up timers, you can realize different scenarios such as:
  • Creating simple animations that make image or text widgets change their contents every couple of seconds

  • Sending notifications to end users at a certain interval

  • Refreshing stories at a certain interval

Multiple timers can exist simultaneously, but each timer works independently from others.

Procedure

  1. In the Scripting section of the Outline panel, choose Start of the navigation path Next navigation step End of the navigation path Timer.

    The side panel Timer opens with a default name Timer_1 displayed. You can change the name at will.

  2. Choose Done to finish adding the timer.
  3. To start the timer in view time, you can use the following API for the canvas, page, popup or widget, for example, the onClick event of a button if you want to start the timer when end users clicks it:
  4. To repeatedly restart a timer once time's out, you can go to its onTimeout event and use the start() API.

    There are some other script APIs available for the onTimeout event of a timer, such as stop() and isRunning(). For detailed information, refer to Story Experience API Reference.

Example

Here's an example of using the timer to automatically scroll images horizontally from right to left at a certain interval.

First, insert three different images, Image_1, Image_2 and Image_3 and place them side by side on the page. Take notes of their left margins, which are 112px, 240px and 368 px.

Then, create an image type script variable Animation_Widgets and an integer type script variable LeftMargins. Enable Set As Array for the two script variables.

After that, add a script object Util_Animation with a function doAnimation and then add a timer Timer_1 .

Write the following scripts:

For the onInitialization event of page:

For doAnimation:

For Timer_1:

When end users view the story, they can soon see the images automatically scroll from right to left in turn.