JavaScript interface for Adobe Captivate

Introduction

Adobe Captivate lets you make more powerful yet leaner content using the new JavaScript Interface feature. This feature gives a common platform for executing JavaScript actions in your projects and adds more powerful interactivity. 

Now, you can write smaller JavaScript snippets to access various variables in the content. You can subscribe to different events generated by the content. 

You can use the JavaScript APIs in two ways: 

  • Run JavaScript actions from the project. 

  • Add JavaScript code to the published HTML at runtime.

Adobe Captivate supports the following objects:

  • cpAPIInterface: Contains utility functions often required to execute JavaScript actions.
  • cpAPIEventEmitter: You can subscribe or unsubscribe to different events generated within the content.
  • cp: Contains utils to trigger object-level actions.

cpAPIInterface

cpAPIEventEmitter is an object available in the window scope. To access the interface object, use window.cpAPIEventEmitter

The following are the methods supported in Adobe Captivate:

Method Description Parameter Usage
getVariableValue Returns the value of the specified variable. 
  window.cpAPIInterface. getVariableValue ("varOne”);
setVariableValue 
Sets the value of a variable name with the specified value. variableName: String
window.cpAPIInterface.setVariableValue ("cpQuizInfoStudentID", "John");
play Plays a project   window.cpAPIInterface. play();
pause Pauses a project   window.cpAPIInterface.pause();
next Go to next slide   window.cpAPIInterface.next();
previous Go to the previous slide   window.cpAPIInterface.previous();
getDurationInSeconds Returns the total duration of the project in seconds. 
  window.cpAPIInterface.getDurationInSeconds();
getEventEmitter Returns the handle to the cpAPIEventEmitter object. 
  window.cpAPIInterface.getEventEmitter();
getCurrentSlideIndex Returns the current slide index of the project.   window.cpAPIInterface.getCurrentSlideIndex();

 

 

Deprecated methods

  • getCurrentFrame
  • GetDurationInFrames

Example 1

In this example, we shall create a variable using the variable creation workflow. Then we will use the new variable, change its value, and print it as an alert message.

Follow the steps to set and get the variable value:

  1. In the Variables screen, create a variable called myVar and assign a value NYC to the variable. 

  2. Add a button on the stage in this project and select Interactions on the right panel. 

  3. In the Action panel, select More > Run JavaScript. Type the following code:

    window.cpAPIInterface.setVariableValue("myVar","BLR");

    var getVar=window.cpAPIInterface.getVariableValue("myVar");

    alert(getVar);

    Here’s what we did:

    • Line 1: We changed the variable's value, myVar, to a new value, BLR. We used the setVariableValue method to change the value.

    • Line 2: We used the method getVariableValue to retrieve the new value set in the previous line. Then we stored the value in a new variable, getVar.

    • Line 3: We display the new value within an alert box. 

  4. Select Done.

  5. Preview the project and select the button. The alert box displays as a popup. 

Example 2

In this example, we will use a system variable, Date.DateMMDDYY, to print the current date. The process remains as documented in the previous example.

In the JavaScript editor, type the code:

dateVar=window.cpAPIInterface.getVariableValue("Date.DateMMDDYY");

alert(dateVar);

When you preview the project and select the button, an alert box displays the current date.

cpAPIEventEmitter

cpAPIEventEmitter is an object available in the window scope. To access the interface object, use window.cpAPIEventEmitter

The following are the methods supported:

Name Description Parameters Usage
add
EventListener
Adds an event listener function to a particular event.
  • eventName : One of the
    event names listed on this page.
  • eventListenerFunction :
    Any JavaScript function.
  • variableName : 
    1. optional. 
    2. One of the Captivate
      variable names whose value change should be notified.
    3. Should only be used with
      CPAPI_
      VARIABLEVALUECHANGED
      event.
  • window.
    cpAPIEventEmitter.
    addEventListener("CPAPI_
    MOVIESTART
    ",
    function(){alert
    ("Movie Started");});
  • window.
    cpAPIEventEmitter.
    addEventListener
    ("CPAPI_VARIABLE
    VALUECHANGED
    ",
    function(){alert("Variable
    Value Changed");},
    "cpQuizInfoStudentID");
remove
EventListener
Removes the event listener function for a particular event.
  • eventName :
    One of the event names listed
    on this page.
  • eventListenerFunction : Any
    JavaScript function.
  • variableName : 
    • optional. 
    • One of the Captivate
      variable name whose value change should be notified.
    • Should only be used with CPAPI_
      VARIABLEVALUECHANGED
      event.
  • window.
    cpAPIEventEmitter.
    removeEventListener
    ("CPAPI_MOVIESTART",
    function()
    {alert("Movie Started");});
  • window.
    cpAPIEventEmitter.
    removeEventListener
    ("CPAPI_VARIABLE
    VALUECHANGED
    ",
    function(){alert
    ("Variable Value Changed");},
    "cpQuizInfoStudentID");

Supported events

List of Events:

Name Description Event Data Enumerations

CPAPI_SLIDEENTER

Notifies that the movie has entered a new slide.

slideNumber=NUMBER;

frameNumber=NUMBER; (Deprecated)

 lcpversion=STRING; (Not supported)

 

CPAPI_SLIDEEXIT

Notifies that the movie is exiting a slide.

slideNumber=NUMBER;

frameNumber=NUMBER; (deprecated)

lcpversion=STRING; (Not supported)

percentageSlideSeen=
NUMBER; (Not supported)

 
CPAPI_
STARTPLAYBARSCRUBBING
Notifies that the user has started seeking the movie using playbar. Not supported  
CPAPI_
ENDPLAYBARSCRUBBING
Notifies that the user has stopped seeking the movie using playbar. Not supported  
CPAPI_INTERACTIVEITEM Notifies that the user has performed an interaction with an interactive item. frameNumber=NUMBER; (deprecated)
includedInQuiz=BOOLEAN; (Not supported)
issuccess=BOOLEAN; (Not supported)
itemname=STRING;
objecttype=NUMBER;
questioneventdata=
[object Object]; (Not supported)
slideNumber=NUMBER;
 
CPAPI_MOVIEPAUSE Notifies that the movie has paused.    
CPAPI_MOVIERESUME Notifies that the movie has resumed from a paused state.    
CPAPI_MOVIESTART Notifies that the movie has started.    
CPAPI_MOVIESTOP Notifies that the movie has stopped. (Not supported)
 
CPAPI_QUESTIONSKIP Notifies that the user has skipped a question slide. correctAnswer=STRING;
infiniteAttempts=BOOLEAN;
interactionID=NUMBER; 
objectiveID=STRING; (Not supported)
questionAnswered=BOOLEAN;
questionAnsweredCorrectly
=BOOLEAN;
questionAttempts=NUMBER;
questionMaxAttempts=NUMBER;
questionMaxScore=NUMBER;
questionNumber=NUMBER;
questionScore=NUMBER;
questionScoringType=
[object Object],{Name:STRING}; (Not supported)
questionType=STRING;
quizName=STRING; (Not supported)
reportAnswers=BOOLEAN; 
selectedAnswer=STRING;
slideNumber=NUMBER;

interactionType - (Not supported)

  • choice
  • true-false
  • fill-in
  • long-fill-in
  • hotspot
  • sequencing
  • matching
  • likert

questionType -

  • choice
  • true-false
  • fill-in
  • long-fill-in
  • hot-spot
  • sequencing
  • matching
  • likert

questionScoringType
["Name"]
 - NOT SUPPORTED

  • PretestQuestion
  • GradedQuestion
  • SurveyQuestion

Supported events:

  • correctAnswer
  • infiniteAttempts
  • interactionID
  • questionAnswered
  • questionAnsweredCorrectly
  • questionAttempts
  • questionMaxAttempts
  • questionMaxScore
  • questionNumber
  • questionScore
  • QuestionType (choice, true-false, long-fill-in, sequencing, matching)
  • reportAnswers
  • selectedAnswer
  • slideNumber
CPAPI_QUESTIONSUBMIT Notifies that the movie has answered a question slide. correctAnswer=STRING;
infiniteAttempts=BOOLEAN;
interactionID=NUMBER; (Not supported)
objectiveID=STRING; (Not supported)
questionAnswered=BOOLEAN;
questionAnsweredCorrectly=
BOOLEAN;
questionAttempts=NUMBER;
questionMaxAttempts=NUMBER;
questionMaxScore=NUMBER;
questionNumber=NUMBER;
questionScore=NUMBER;
questionScoringType=[object Object],{Name:STRING}; (Not supported)
questionType=STRING;
quizName=STRING; (Not supported)
reportAnswers=BOOLEAN; 
selectedAnswer=STRING; 
slideNumber=NUMBER;

Supported events:

  • correctAnswer
  • infiniteAttempts
  • interactionID
  • questionAnswered
  • questionAnsweredCorrectly
  • questionAttempts
  • questionMaxAttempts
  • questionMaxScore
  • questionNumber
  • questionScore
  • QuestionType (choice, true-false, long-fill-in, sequencing, matching)
  • reportAnswers
  • selectedAnswer
  • slideNumber
CPAPI_
VARIABLEVALUECHANGED

Subscribing to this event requires an additional parameter - variableName. Once subscribed, any change to the value of the supplied variable will be notified.

captivateVersion=STRING; (Not supported)
varName=STRING;
oldVal=STRING;
newVal=STRING;

 

Example

Start an event emitter for the event CPAPI_VARIABLEVALUECHANGED. When triggered, it alerts the status of a radio button group, whether the first or second option is selected.

var alertEvent = function(){alert("Variable Value Changed")};

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED", alertEvent , "radioOption1");

For the radio button group, use the following JS code for the selection events:

Button 1

window.cpAPIInterface.setVariableValue("radioOption1", 'You have selected first option');

Button 2

var option1 = window.cpAPIInterface.getVariableValue("radioOption1"); 

window.cpAPIInterface.setVariableValue("radioOption1", 'You have selected second option')

cp

Trigger object-level actions. The following are the methods supported:

  • show

  • hide

Example

cp.hide("ss1"); // hide object ss1

cp.show("ss2"); // show object ss2

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online