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

JavaScript issue - error with setVariableValue

Contributor ,
Oct 10, 2016 Oct 10, 2016

Copy link to clipboard

Copied

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!

Views

416

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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