Skip navigation
Currently Being Moderated

JavaScript and Advanced Actions

Jul 31, 2012 8:30 AM

I'm trying to achieve the following in Captivate 6.0:


  1. Display an animated gif of dice on a Captivate slide [working]
  2. On click:
    1. Generate a number 1-6 as the result of 'rolling the dice' and assign it to a variable [working]
    2. Show / hide elements on the page so the user can see the result of their roll, and a Next button so they can proceed [not working]


I have tried to achieve the Show / Hide by:

  • Jumping back to the current slide, using JavaScript and
  • Calling an advanced action On Enter for the slide, that checks if the dice value has been set and then Show / Hide objects as desired.


Unfortunately, it appears when I jump back to the same slide using JavaScript, the On Enter event is not being called. If I click back then forward on the playbar, I see the desired result.


I have included the JavaScript and Advanced Action (being set On Enter for the slide) below.


Is there a way to:

  1. Update the JavaScript so that when I jump back to the current slide, On Enter is executed? OR
  2. Call my advanced action directly from JavaScript? OR
  3. Achieve the desired result in some other way ... I'm not particularly fussed whether I used JavaScript or Advanced Actions to achieve it!!


Here are the details:


Variable (Set through Project --> Variables...)

Dice_Value = -1


Advanced Action (On Enter)


If Dice_Value is greater than or equal to 1

Hide Dice_Animation

Hide Dice_Click_Box

Show Dice_Value_Text

Show Dice_Next

Show Dice_Next_Caption


Show Dice_Animation
Show Dice_Click_Box
Hide Dice_Value_Text
Hide Dice_Next
Hide Dice_Next_Caption


JavaScript (Called when the dice animation is clicked)


function rollTheDice(){

var cpObj = document.Captivate;
var diceValue = 1;
var currentTime = cpObj.cpEIGetValue('cpInfoCurrentTime');
var lastDigit = parseInt(currentTime.charAt(7));
switch(lastDigit) {

case 7:

diceValue = 1;

case 8:

diceValue = 2;

case 9:

diceValue = 4;

case 0:

diceValue = 5;


diceValue = lastDigit;

cpObj.cpEISetValue('m_VarHandle.Dice_Value', diceValue);
cpObj.cpEISetValue('cpCmndGotoSlide',cpObj.cpEIGetValue('rdinfoCurrent Slide'));



  • Currently Being Moderated
    Jul 31, 2012 8:32 AM   in reply to sarbarker

    If you get back to the first frame of a slide, the advanced action triggered by the On Enter event is not executed. I'm an advanced action user, Javascript is still little bit of a mystery to me. If I want an On Enter action to be repeated, I will get back to the slide before the slide and with a conditional action (slide has already been visited, thus setting a variable and checking that one) get it immediately to the next slide. That way the on enter event is repeated. Did not check it yet, but perhaps navigating to the frame before the first frame of the present slide will work as well (micro-navigation), something I have to try out because maybe you need to get a couple of frames more backwards.



    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 8:53 AM   in reply to sarbarker

    You're welcome. I really need to practice Javascript, took a course with code academy but didn't find time to practice;



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points