Making an Action Conditional

Description

In our Action Script, the second Action which displays the message box executes even if the user clicks the cancel button when prompted for his or her name. Try this:

Some of the examples in this guide require the "Learning Action Scripting" workspace. See Creating Your First Action Script to learn how to get the "Learning Action Scripting" workspace installed.

  1. Select the "Lesson1" script in the Control Panel, and click the Run button. Alpha Anywhere displays the prompt for the user name.

  2. Click the Cancel button. Alpha Anywhere displays the message box:

    images/Conditional_action_1.gif

This, of course, is not what you want. You want to suppress this message box from appearing if the user clicks the Cancel button (or you might want to display an entirely different message box).

Alpha Anywhere lets you specify conditions for each Action in an Action Script. For each action in the script, Alpha Anywhere evaluates the condition at run-time and decides whether or not to execute that condition.

If the user clicks the Cancel button in the Prompt for Text Action, the variable set by this action will be blank (i.e has a NULL value). Therefore, we want to display the message box only if the variable is not NULL.

Here is how to accomplish this:

  1. Dismiss the Welcome dialog box.

  2. Click the "Lesson1" script in the Control Panel and then click the Design button.

  3. Click the If Show/hide Conditions button. This is a toggle button, so now it appears pressed. Once the Show/hide Conditions button is pressed, the Action Script Editor shows a new column for each action.

    images/Conditional_action_2.gif
    The green check mark next to each action indicates that the action is not conditional. In other words, the action will always be executed. To make the Display a Message Box Action conditional.
  4. Select the "Display a Message Box" Action.

  5. Check the Action is conditional box to make the "Display a Message Box Action" conditional. When you do this, additional prompts on the Code Editor become visible.

    images/Conditional_action_3.gif
  6. In addition, the icon to the left of the Action changes to an orange ? mark, indicating that the Action is conditional.

    images/Conditional_action_4.gif

    Alpha Anywhere offers two kinds of conditional tests. It will execute the current action if either:

    A flag variable is True

    A condition expression is True

    In this case you want the "Condition Expression is True" option. (The "Flag variable is True" option will be described later).

  7. Click the Expression Builder button at the Expression prompt.

    images/Conditional_action_7.gif
  8. Enter the expression: Var->vcName <> "".

  9. Click OK to close the Expression Builder. Your screen should now look like this:

    images/Conditional_action_8.gif
  10. Click the Save Script button to save the script (but do not close the Code Editor ).

  11. Test the script by clicking the Run Script button. Click the Cancel button when prompted for a name. Now the previous message box no longer appears.

Limitations

Desktop Applications Only