Events and Actions

This page explains how to use command variables that allow you to call advanced actions, sometimes in response to certain events.

Note: The xcmndAddEventListener and xcmndRemoveEventListener command variables are essentially expansions of the xcmndCallActionOn command variable. It is therefore highly recommended you have a solid understanding of the xcmndCallActionOn command variable before learning how to use xcmndAddEventListener and xcmndRemoveEventListener.

xcmndCallActionOn

​Parameters

  1. Name of Interactive Object
  2. Name of Criteria - success (default), failure, onfocuslost

Description

This variable was created so that one Advanced Action could trigger another Advanced Action, something that was impossible before.

The ideal way that this variable would work would be that you assign this variable the name of an Advanced Action. BUT, as it turns out there is no where in the HTML5 export that Advanced Actions are ordered into a list. Instead, at export the Advanced Action is converted into JavaScript and then attached to whatever Interactive Object is calling it.

So unfortunately assigning this command variable the name of an Advanced Action does not allow it to call that Advanced Action. Instead this command variable needs two parameters.

  1. Name of an Interactive Object (Buttons, click boxes, text entry boxes, certain widgets, shape buttons)
  2. Name of Criteria (A button can call a success action, or it can call a failure (last attempt) action. Success and failure are different types of criteria. Text Entry Boxes have a third type of criteria called on focus lost)

So if you want to call the success action attached to a button called Button_1, you could do so with the following code.

Assign | xcmndCallActionOn with Button_1, success

If you wanted to call the failure action on Button_1, you would do so in the following way.

Assign | xcmndCallActionOn with Button_1, failure

If you only provide the first parameter (the interactive object name) and don't provide the second parameter (the criteria name), xcmndCallAction will assume you want to call the interactive object's success action. Therefore the following code...

Assign | xcmndCallActionOn with Button_1

...will call Button_1's success action.

Note: If Button_1's success action as NOT an Advanced Action, but instead a Jump To Next Slide action, xcmndCallActionOn will still enact that Jump To Next Slide Action. Also, if the success action was instead an Assign call, and the Continue Playing the Project checkbox was selected, xcmndCallActionOn will perform the Assign action AND start the project playing again.

Also Note: Button_1 does not have to be on the current slide for this code to work. We recommend you create a slide in your course which will never get visited and place all these "proxy buttons" there.

xcmndAddEventListener

Parameters

  1. The name of a slide object OR an @syntax query OR the name of a variable that contains slide object name / @syntax query.
  2. Name of an event (Valid events listed here)
  3. Name of Interactive Object
  4. Name of Criteria - success (default), failure, onfocuslost

Features

  • Uses @syntax
  • Some parameters can be replaced with variables

Description

xcmndAddEventListener is basically the xcmndCallActionOn command variable with two extra parameters. While xcmndCallActionOn allows you to specify WHAT action you want to call, xcmndAddEventListener allows you to specify WHEN to call it.

For example, just like in the xcmndCallActionOn description, you have a button called Button_1, and you want to call its success action. But, you want that actions to be called want to call an action when the user clicks on Shape_1.

That can be done with the following code.

Assign | xcmndAddEventListener with Shape_1, click, Button_1, success

That's telling xcmndAddEventListener: When Shape_1 is clicked, call the success action on Button_1. If you then click Shape_1 again, it will call that action a second time. This will continue to happen until you use xcmndRemoveEventListener to deregister this event.

If, instead, you wanted to call Button_1's failure action, that can be done in the following way: 

Assign | xcmndAddEventListener with Shape_1, click, Button_1, failure

Also, just like xcmndCallActionOn, if the last parameter is not provided, xcmndAddEventListener will assume you want to call the success action. So the following code...

Assign | xcmndAddEventListener with Shape_1, click, Button_1

...will call Button_1's success action when Shape_1 is clicked.

The First Parameter in Detail

Usually the first parameter will take a slide object's item name. It can also however, accept an @syntax query.

Let's say ou had a slide with objects named Shape_1, Shape_2, and Shape_3. If you then executed the following code...

Assign | xcmndAddEventListener with Shape_@, click, Button_1, success

...clicking any of those shapes would cause Button_1's success action to be called.

Alternatively, instead of providing a slide object name, you could provide the name of a variable. That variable's value must contain either a slide object name OR an @syntax query.

To extend our example, let's say you had a variable named MyVar in your project. In that case after executing the following code...

Assign | MyVar with Shape_2
Assign | xcmndAddEventListener with MyVar, click, Button_1, success

...clicking on Shape_2 would cause Button_1's success action to be called.

Also, after executing the following code...

Assign | MyVar with Shape_@
Assign | xcmndAddEventListener with MyVar, click, Button_1, success

...click on Shape_1, Shape_2, and Shape_3 would cause Button_1's success action to be called.

The Second Parameter in Detail

The following is a list of valid event names (Note: Some have multiple names that point to the same event):

  • Rollover OR Mouse over
  • Rollout OR Mouse out
  • Mouse Down
  • Mouse Up
  • Click
  • Double Click OR Dblclick
  • Right Click

This parameter is NOT case sensitive.

xcmndRemoveEventListener

Parameters

  1. The name of a slide object OR an @syntax query OR the name of a variable that contains slide object name / @syntax query.
  2. Name of an event (Valid events listed here)
  3. Name of Interactive Object
  4. Name of Criteria - success (default), failure, onfocuslost

Features

  • Uses @syntax
  • Some parameters can be replaced with variables

Description

xcmndRemoveEventListener is the mirror image of xcmndAddEventListener.

If you used xcmndAddEventListener like so:

Assign | xcmndAddEventListener with Shape_1, click, Button_1, success

It would cause Button_1's success action to be called every time you clicked Shape_1.

If at a later time you want to stop that behaviour, you would pass xcmndRemoveEventListener those exact same details.

Assign | xcmndRemoveEventListener with Shape_1, click, Button_1, success

xcmndRemoveEventListener's parameters work exactly the same as xcmndAddEventListener's.

IF YOU LIKE WHAT YOU'VE READ ABOVE, THERE'S PLENTY MORE!

Join more than 2500 other Adobe Captivate users just like yourself and receive regular troubleshooting tips, illustrated tutorials, technical information, and creative solutions to real-world e-learning development issues. (See an example here.) Click the button below to join our community.  It's completely FREE!