Navigation:  Examples >

Example 5: Using Delay

Previous pageReturn to chapter overviewNext page

Example 5: Using Delay

Run This Example in New Window

Sometimes you may want to pause a while between two actions.  Delay is a flow control that designed for this use case.

example05_delay

Delay can be placed under event or other flow controls.  You can put some actions under the delay, or after the delay, these two ways are equivalent, you can choose any one you like:

example05_two_ways_to_delay

Let create an interesting example: show a number when clicking on a button, hide it after 2 seconds.

First we need to place a TextBox and a Button element in the page.  Put a long number in the TextBox and change the text of Button to "Show Number".  Don't forget to unselect the "visible" checkbox for the TextBox element (so it will be hidden by default):

example05_elements

Create the behavior for the button (Button_1) and add "Element Clicked" event.  Choose "Operate on Element..." after clicking "Add Action" button in toolbar.

example05_add_behavior

Choose the TextBox element (TextBox_1) as the target element, select "Change Visibility" action and then select "Make Element Visible" as parameter.  This action will make the TextBox element visible.

example05_operate_on_textbox

After creating the action, we can select the "Element Clicked" event again and add a delay by clicking the "Add Flow Control" button in toolbar.

example05_add_delay

You will see the window below if you select "Delay for a While".  Please input 2000 (2 seconds) and click "Ok" button.

example05_delay_param

Then we add another action to hide the TextBox element again.

example05_add_hide_action

Fill the action editor window like this:

example05_hide_action

Ok, below is the final behavior definition:

example05_final_behavior

Now you can run the simulation and see how it works.  You can view this online example to see the result, or download the plot file.