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

JavaScript and Advanced Actions

Guest
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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

Else

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

case 8:

diceValue = 2;
break;

case 9:

diceValue = 4;
break;

case 0:

diceValue = 5;
break;

default:

diceValue = lastDigit;
break;

}
cpObj.cpEISetValue('m_VarHandle.Dice_Value', diceValue);
cpObj.cpEISetValue('cpCmndGotoSlide',cpObj.cpEIGetValue('rdinfoCurrentSlide'));
cpObj.cpEISetValue('rdcmndResume',1);

}

rollTheDice();

Views

846

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

correct answers 1 Correct answer

Community Expert , Jul 31, 2012 Jul 31, 2012

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, bu

...

Votes

Translate

Translate
Community Expert ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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.

Lilybiri

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
Guest
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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!

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
Community Expert ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

LATEST

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

Lilybiri

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