Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScript issue - error with setVariableValue

Contributor ,
Oct 10, 2016 Oct 10, 2016

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!

443
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 11, 2016 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 11, 2016 Oct 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 11, 2016 Oct 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 11, 2016 Oct 11, 2016
LATEST

Thanks - I'll get back to that fire shortly.

Some of the courses where this will be used will be in an LMS. So far, this testing has not gone to that step.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources