Skip to main content
AP_AW
Inspiring
September 8, 2016
Answered

JavaScript calling Advanced Action

  • September 8, 2016
  • 2 replies
  • 2056 views

I've created an advanced action that I've called "showMe".

Then I tried to trigger it in JavaScript. I tried

cp.runJavascript("showMe");

cp.runJavascript(showMe);

and

cp.runJavascript(cp.model.data.showMe.oca); (yep, I'm guessing).

but they all just give JavaScript errors.

How do I call and advanced action in Cp 9 using JavaScript?

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    The cp.runJavascript needs another argument "_self", but it still will not work.

    The advanced action "showMe" name only exists in the IDE, not in the HTML5 output. The only thing that exists in the code is all of the JavaScript or cpCommands that make up the advanced action, ie:

    cp.show("something");

    cp.runJavascript("someFunction()", "_self")

    cp.jumpToNextSlide()

    You are on track using the "oca" but the implementation is wrong. You need to find the element that has the specific "oca" property.

    cp.runJavascript(cp.model.data.slideID.elementID.oca, "_self");

    If you have a button say "cc_btn" that is set to display for the rest of the project, it would be:

    cp.runJavascript(cp.model.data.cc_btn.oca, "_self");

    It all depends on what is triggering the advanced action. You may need to first get the slide id, the once you have that you can iterate through it's "si" property to get the element and then the "oca" property.

    2 replies

    AP_AW
    AP_AWAuthor
    Inspiring
    September 8, 2016

    One other question, how do I get the ID of the current slide?

    TLCMediaDesign
    Inspiring
    September 8, 2016

    There are a couple of ways to get the current slide ID.

    I AWAYS use a slide enter event listener in every project. If you use this you can get the current slide id from the event data:

    var currentSlideID = 'Slide' + e.Data.id;

    The other way is to parse the project slides string:

    var getSlides = cp.model.data.project_main.slides;

    var currentSlideID = getSlides.split(",")[window.cpInfoCurrentSlide - 1 ];

    I've gotten to the point where we never create advanced action anymore. Everything is done dynamically through JavaScript. We use naming conventions for slide and objects and run JavaScript based on those. Our quizzes are even built this way, there are no advanced action to evaluated them, just create a "correct answer" variable and name the elements correctly.

    I would highly suggest you attach a JS file with the enter slide listener at a minimum, also the variable change and interactive item submit listeners. Use this a basis for every project and you can monitor all kinds of things like showing or hiding a next button.

    AP_AW
    AP_AWAuthor
    Inspiring
    September 9, 2016

    Ok, I think I understand why you don't have any advanced actions in your courses. I added a number of advanced actions to a course but I didn't associate them with any element then they didn't get published.

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    September 8, 2016

    The cp.runJavascript needs another argument "_self", but it still will not work.

    The advanced action "showMe" name only exists in the IDE, not in the HTML5 output. The only thing that exists in the code is all of the JavaScript or cpCommands that make up the advanced action, ie:

    cp.show("something");

    cp.runJavascript("someFunction()", "_self")

    cp.jumpToNextSlide()

    You are on track using the "oca" but the implementation is wrong. You need to find the element that has the specific "oca" property.

    cp.runJavascript(cp.model.data.slideID.elementID.oca, "_self");

    If you have a button say "cc_btn" that is set to display for the rest of the project, it would be:

    cp.runJavascript(cp.model.data.cc_btn.oca, "_self");

    It all depends on what is triggering the advanced action. You may need to first get the slide id, the once you have that you can iterate through it's "si" property to get the element and then the "oca" property.

    AP_AW
    AP_AWAuthor
    Inspiring
    September 8, 2016

    Thanks. I've written some js which will be called on, more or less, each slide. Some of the slides were to have a callback to an advanced action. I was thinking I could just call the js and pass the name of the advanced action as a parameter.

    ---

    I just ran a quick test and the advanced action was added as an "sea" and not an "oca" property to the slide???