3 Replies Latest reply: Jul 31, 2012 8:53 AM by Lilybiri RSS

    JavaScript and Advanced Actions


      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);



        • 1. Re: JavaScript and Advanced Actions
          Lilybiri ACP/MVPs

          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.



          • 2. Re: JavaScript and Advanced Actions
            sarbarker Community Member

            Thanks Lilybiri!


            It was really useful to get your confirmation that 'If you get back to the first frame of a slide, the advanced action triggered by the On Enter event is not executed.' This means I'm not going cRaZy!


            It gets a bit complicated as there are a few slides that might navigate to this slide (I'm building a Choose Your Own Adventure). So, there was no clear 'previous' slide to work with. Based on a few blogs (including your own) I have now done it this way:

            • At the end of the Javascript, jumped to a dummy slide
            • One the dummy slide, set Time 0.2 sec, On Enter = Continue (probably not called!), On Exit = Jump To "Dice Slide".


            It works well. Thanks again for your prompt response!

            • 3. Re: JavaScript and Advanced Actions
              Lilybiri ACP/MVPs

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