Copy link to clipboard
Copied
Hello,
I want to develop combination of quiz questions and test me simulations in Captivate. And send the results to external JavaScript so I can save them to the Database.
I published the Captivate to HTML5, typed this code in an external .js file and linked it to index.html, but I'm only getting the alert "no CPI interface" as the interface is not detected I think. I'm testing it from a local web server. Any ideas?
==============================================================================
var interfaceObj;
var eventEmitterObj;
window.addEventListener("moduleReadyEvent", function(evt)
{
//evt.Data carries the interface object.
//It is same as window.cpAPIInterface
interfaceObj = evt.Data;
eventEmitterObj = interfaceObj.getEventEmitter();
});
//check if window.cpAPIInterface is available
if(interfaceObj)
{
//check if window.cpAPIEventEmitter is available
if(eventEmitterObj)
{
//add a listener to CPAPI_SLIDEENTER event
eventEmitterObj.addEventListener("CPAPI_SLIDEENTER",function(e)
{
var cAns = interfaceObj.getVariableValue("slideNumber");
alert(cAns);
//window.cpAPIInterface.setVariableValue("mySlideVisitCounter",lSlideVisitCtr);
});
}
}else{
alert("No CPI interface")
}
The data you are speaking of is in the event, not the window.
eventEmitterObj.addEventListener( 'CPAPI_QUESTIONSUBMIT', function ( e ){
var cAns = e.Data.correctAnswer;
alert("correctAnswer="+cAns);
Copy link to clipboard
Copied
The interfaceObj is not the same as the cpAPIInterface object. All of the Captivate variable are in the window object. Try this:
var interfaceObj, eventEmitterObj;
window.addEventListener( 'moduleReadyEvent', function ( e )
{
interfaceObj = e.Data;
eventEmitterObj = interfaceObj.getEventEmitter();
initializeEventListeners();
});
function initializeEventListeners()
{
if ( interfaceObj )
{
if ( eventEmitterObj )
{
eventEmitterObj.addEventListener( 'CPAPI_SLIDEENTER', function ( e )
{
var cAns = window.slideNumber;
alert(cAns);
//window.cpAPIInterface.setVariableValue("mySlideVisitCounter",lSlideVisitCtr);
});
}
}
}
Copy link to clipboard
Copied
Hi TLCMediaDesign, Thanks for the solution. I tried it but it returns an undefined value.
eventEmitterObj.addEventListener( 'CPAPI_QUESTIONSUBMIT', function ( e ){
var cAns = window.correctAnswer;
alert("correctAnswer="+cAns);
Copy link to clipboard
Copied
What are you using to populate correctAnswer?
Copy link to clipboard
Copied
I'm using the Captivate event data "correctAnswer" as listed on the Adobe URL Common JS interface . So the event is CPAPI_QUESTIONSUBMIT and event data is "correctAnswer". Do I need to separately define this variable in Captivate? I thought it will be automatically populating values from the quiz.
Copy link to clipboard
Copied
I have also tried populating a custom variable and then read that variable in Javascript. But it returns an empty value. If I publish for SCORM then it returns "undefined".
Copy link to clipboard
Copied
The data you are speaking of is in the event, not the window.
eventEmitterObj.addEventListener( 'CPAPI_QUESTIONSUBMIT', function ( e ){
var cAns = e.Data.correctAnswer;
alert("correctAnswer="+cAns);
Copy link to clipboard
Copied
Awesome! that worked. Thank you so much. Really appreciate it.
Copy link to clipboard
Copied
How did you link the external .js file to the index? Where exactly? And where did you put the .js file?
I would like to recall the function written in my .js file in my Scorm through an hyperlink that execute a simple javascript code: the code should assign the variable, recall the function (in the .js file) and make it work with the assigned variable. Could you help me?
Copy link to clipboard
Copied
You'll need to edit the html template file located here:
C:\Program Files\Adobe\Adobe Captivate ## x64\HTML\index.html
Add the following include to the head section:
<script src="assets/js/yourfile.js"></script>
Then drop your JavaScript file in the folder:
C:\Program Files\Adobe\Adobe Captivate ## x64\HTMLassets\js\
If the folder does not exist, create it.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more