The following tutorial helps you get started with using scripting in Adobe Captivate.

You have been asked to create a login slide with fields to enter the user name and password.

When the user enters the correct values, the following actions take place:

  • The project moves to the next slide.

  • A text caption in the next slide displays the message, "Welcome <user name>".

  • The default e-mail editor opens with the e-mail ID of the person that must be informed of the login.

When the user enters incorrect information, a text caption is displayed asking the user to reenter information.

Create variables for the project

  1. Select Project > Variables.

  2. Create a variable named varUserName, with the value user. For more information, see Create a user-defined variable.

  3. Create a variable named varPassword with the value password.

Create objects for the slides

  1. In an open project, insert two text entry boxes for the user name and password. The text entry boxes must be set to act as form fields.

    Note:

    To set a text entry box to act as a form field, select it and then deselect Validate User Input in the Property Inspector.  

  2. Delete the Submit button from the User Name field.

  3. Set the following options for user name:

    • In Actions, go to On Success, and select No Action.

    • Deselect Infinite Attempts.

    Note:

    This option is disabled automatically when you disable Validate User Input.

    • In the Action area of the Property Inspector, select Continue in the Last Attempt field.
    • Associate the field with the variable varUserName in the Var Associated field (General area of the Property Inspector).
  4. Double-click the text entry field for the password, and set the following options:

    • In the On Success field, select Continue.

    • Deselect Infinite Attempts.

    • In the After Last Attempt menu, select Continue.

    • In Variable Associated, select varPassword.

  5. Insert a text caption and do the following:

    • Enter the following text on the caption: Invalid username/password. Please try again.

    • In Name, change the name of the caption to FailureCaption. Deselect the Visible option. Doing so hides the caption until the conditions in the script enable the caption.

  6. Insert a blank slide.

  7. Insert a text caption with the text Welcome and the variable varUserName in the format Welcome $$varUserName$$.

  8. Save the project as variables.cp.

Create an advanced action for the login slide

The advanced action for the login slide must do the following:

  • Check whether the correct information has been entered in the login and password fields.

  • Move to the next slide if the information is correct.

  • Stay at the login slide if the information is incorrect and display a text caption requesting the user to reenter the login information.

  1. Select Project > Advanced Actions.

  2. In the script window, do the following:

    1. Click Conditional Actions as the Action Type.

    2. Specify the name of the script as ‘validate’.

    3. In the IF section, double-click the rows and select the appropriate options in the drop-down lists. See the following illustration for the options to select:

      IF condition in the ‘validate’ advanced action
      IF condition in the ‘validate’ advanced action

    4. In the Actions section, double-click the first row and specify the action as Continue.

    5. Click the Else header, double-click the rows, and specify the appropriate options as shown below.

      ELSE condition in the ‘validate’ advanced action
      ELSE condition in the ‘validate’ advanced action

Now look at individual lines of the code to understand what they do.

Lines of code in the IF condition
Lines of code in the IF condition

The code checks whether the user has used the user and password login credentials in the respective fields.

Action performed when IF conditions are true
Action performed when IF conditions are true

This project moves to the next slide if the user name and password are entered correctly.

Lines of code in the ELSE condition
Lines of code in the ELSE condition

If the user information is incorrect, the project stays at the login slide. The text caption with the name FailureCaption is displayed.

Create an advanced action for the e-mail and welcome slide

In the script window, do the following:

create a script named sequential action with the following code:

  1. Click Standard Actions as the Action Type.

  2. Specify the name of the script as ‘sequentialaction’.

  3. Double-click the rows and specify the options as shown below.

Lines of code in ‘sequential action’
Lines of code in ‘sequential action’

Now look at individual lines of the code to understand what they do.

First line of code in ‘sequential action’
First line of code in ‘sequential action’

On successful login, the code opens up the default e-mail editor with the e-mail ID xyz@company.com displayed in the To field.

Second line of code in ‘sequential action’
Second line of code in ‘sequential action’

Displays the text caption containing the text, "Welcome <login name>".

Apply the advanced action to the login slide

  • Double-click the login slide, and set the following actions in the Property Inspector:

    • On Enter: Select Continue.

    • On Exit: Select Execute Advanced Actions, and in the Action menu, select Validate.

Apply the advanced action to the next slide after login

  • Double-click the display slide, and in the Property Inspector, set the following actions:

    • On Enter: Select Execute Advanced Action, and choose sequential action in the Action menu.

    • On Exit: select Go To Next Slide.

Run the project, and check whether the aims of the project have been achieved.

More tutorials and examples

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy