Skip to main content
Jefferbob12055564
Inspiring
October 10, 2016
Question

JavaScript issue - error with setVariableValue

  • October 10, 2016
  • 1 reply
  • 625 views

Specs:

Captivate 9.0.2.421

Publishing to SWF

Testing by publishing to server

Testing with latest Chrome

Problem code line:

window.cpAPIInterface.setVariableValue("urlparam1", "NotDefined");

If I add this with or without other code in the script window on a slide - it works fine.

If I try to add it anywhere in the standard.js file, the standard.htm file script block, or an external js file linked to standard.htm - it fails; Chrome console throws this error on that line:

Uncaught TypeError: Cannot read property 'setVariableValue' of undefined

Old programmer, but not as big on JS. I'm sure it's something stupid/minor, but I'm pulling out what little hair I have left. Thanks!

This topic has been closed for replies.

1 reply

TLCMediaDesign
Inspiring
October 11, 2016

Is the code wrapped in a function or just in the file?

If it's throwing that error the cpAPIInterface object has not been created yet.

Jefferbob12055564
Inspiring
October 11, 2016

Currently, just in the file, but I also tried it in a function and it wouldn't invoke with a call from within Captivate.

At what point does that object get instantiated?

TLCMediaDesign
Inspiring
October 11, 2016

It seems like it is created with a call from the SWF.

It should work if you include a function in the standard.js and call that from Captivate.

function getVar()

{

window.cpAPIInterface.setVariableValue("urlparam1", "NotDefined");

}

Are you running this in an LMS?