Skip to main content
Inspiring
September 18, 2018
Answered

GoTo Slide by Slide Label

  • September 18, 2018
  • 4 replies
  • 2643 views

Hi there,

Anybody knows of a way to jump to a specific slide by specifying the slide label rather then the slide number; maybe some hidden/undocumented method similar to cpCmndGotoSlideByUIDAndResume ?

(No, replacing UID by Label in the above doesn't work )

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    You can do it but in my experience you need external JavaScript to safely execute for loops.

    You can get all of the labels, parse through them and jump.

    You can use this function in an external js file:

    function jumpSlideLabel(which)

    {

         var idx = 0;

         var getSlides = cp.model.data.project_main.slides.split(",");

         for ( var i = 0; I < getSlides.length' I++ )

         {

              if ( cp.model.data[getSlides].lb === which )

              {

                   window.cpCmndGotoSlide = i;

                   window.cpCmndResume = 1;

                   break;

              }

    }

    In Captivate, call the function with the argument as the label:

    jumpSlideLabel("Slide label");

    4 replies

    Known Participant
    January 29, 2020

    Hi TLCMediaDesign, I'm very concerned upon reading this:

    You can do it but in my experience you need external JavaScript to safely execute for loops.

     

    I'm in the process of setting up a course structure dependent on JavaScript to function correctly. The customer do not wish to use external js. Does this mean I cannot count on my for loops running correctly from the script window and are there other major pitfalls as basic as this using the script window?

     

    Hope for a quick response! Thanks Jorgen

    GaanfAuthor
    Inspiring
    January 30, 2020

    I think TLCMediaDesign refers to the issue that certain characters are not properly escaped when entered into the Script Window inside Advanced Actions (the Script Window on simple actions doesn't seem to suffer from that). Among those problematic charcters is '<', which is frequently used when writing a loop; e.g.:

    for (i = 0; i < 10; i++) {
      [do something];
    }

     

    In case you want or need to stay clear of external JavaScript for whatever reason, here's a work-around:

    Write out the code in an external editor first, then replace '<' by...

    '&lt;' (HTML Number for '<') or
    '&#60;' (HTML Name for '<')

    ...before copying the code over to the Script Window in an Advanced Action. On saving the Script Window, those strings will be properly escaped and converted to the '<' character. Note that you'll have to cover all '<' character occurrences in the code at once in every copy and past action. You can't just edit/add one of several occurrences that way, so it's probably good advise to always copy the entire code to a blank Script Window in one shot.
    You can also type the HTML Number/Name strings directly into the Script Window, but again you'd have to make sure to enter all occurrences in one shot.

    See also https://forums.adobe.com/message/10709838 

     

    Known Participant
    January 30, 2020

    Hi and thanks a lot for your reply, I'm only using the script window that is avaliable On Enter: Execute Javascript > Script Window. Everything seems to work fine on different devices etc, but got concerned when I read that loops should be done in external Javascript and the script window might not be 100% reliable. 

     
    So I guess I don't have to worry then as long as I stay away from the one inside advanced actions, phew! 😄
     
    Cheers Jorgen
    Inspiring
    September 18, 2018

    I'm not well-versed enough in code yet to understand how all this works, but I thought I'd share another piece of code that I found on a forum (did not write it myself) that has worked well for me so far. It should be noted, I've never put this code directly into Captivate, I use it in an Animate project then export as an .oam file and add that to captivate.

    function gotoSlideNamed(aName) {

       var cpObjectList = Object.getOwnPropertyNames(window.parent.window.cp.D); 

       var findSlideLabels = function ( acc, val ) {

             if ( typeof window.parent.window.cp.D[val].lb == "undefined" || window.parent.window.cp.D[val].lb == "" ) return acc;

              acc[window.parent.window.cp.D[val].lb ] = window.parent.window.cp.D[val].from ;

              return acc

              }

       var cpSlideObjects = cpObjectList.reduce ( findSlideLabels , {} )

       window.parent.window.cpCmndGotoFrameAndResume = cpSlideObjects[aName];

       return ;

    }

    then just call

    gotoSlideNamed("YourSlideName");

    TLC's looks shorter though, I may try that out as well and see how it goes!

    TLCMediaDesign
    Inspiring
    September 19, 2018

    This code only would work if the code is running in an iFrame.

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    September 18, 2018

    You can do it but in my experience you need external JavaScript to safely execute for loops.

    You can get all of the labels, parse through them and jump.

    You can use this function in an external js file:

    function jumpSlideLabel(which)

    {

         var idx = 0;

         var getSlides = cp.model.data.project_main.slides.split(",");

         for ( var i = 0; I < getSlides.length' I++ )

         {

              if ( cp.model.data[getSlides].lb === which )

              {

                   window.cpCmndGotoSlide = i;

                   window.cpCmndResume = 1;

                   break;

              }

    }

    In Captivate, call the function with the argument as the label:

    jumpSlideLabel("Slide label");

    GaanfAuthor
    Inspiring
    September 18, 2018

    Thanks a lot, I'll give that a try.

    Lilybiri
    Brainiac
    September 18, 2018

    I always use Jump to slide with slide labels, never with nubmers. But of course I only use shared or advanced actions for such simple navigations.  Sorry....

    GaanfAuthor
    Inspiring
    September 18, 2018

    Thanks, Lilibyri.

    Yes, I know that Captivate presents number as well as labels in the selectors when using simple or advanced actions. I was more looking for something that can be used in a script.

    Lilybiri
    Brainiac
    September 18, 2018

    Advanced actions and shared actions are scripts, since they become JS when published. It is a pity that we cannot 'read(' the converted scripts. You know my point of view: why use JS when it can be done with those actions? You could maybe create an array to link the slide numbers to the slide labels? It looks like advanced actions have a way to link both.