Skip to main content
Known Participant
July 7, 2016
Question

Can I loop through slides with javascript?

  • July 7, 2016
  • 1 reply
  • 2040 views

What I would like to do is to jump to a slide (perhaps using cpCmndGotoSlide) using a slide label string rather than a number.  e.g.  cpCmndGotoSlide('Demo Slide 6')

Because the slide label string will be determined in runtime,   my idea was to loop through the slide javascript objects, if they exist, looking for the slide with this slide label  (e.g.  slide5.slideLabel) , and then geting the corresponding slide number (e.g. slide5.slideNumber) so that I can use that number to jump to the correct slide....

Thanks for any help / ideas!

This topic has been closed for replies.

1 reply

Lilybiri
Legend
July 7, 2016

Can you explain how you mean by 'slide label string will be determined in runtime'? And also what you mean by "loop" because in my understanding looping means that slides will be played in sequence without user actions, which is exactly what Captivate does when you do not pause any slide.

If you use a shared action with the slide label as parameter, could that not work?

Inspiring
July 7, 2016

Hi Lilybiri,

I have a button on a master slide.

Here is what I want to have happen when the user clicks on it:

  1. determine the name of the current slide --> You can do this with cpInfoCurrentSlideLabel  --> e.g. "4 Intro"
  2. get the number from that label --> You can do this with JavaScript  --> e.g. "4"
  3. with this number create a new string --> You can do this with JS --> e.g. 4 + " Content" --> "4 Content"
  4. jump to the slide with this new string as a slide label using cpCmndGotoSlide -->  as far as I know you need an integer to pass into cpCmndGotoSlide; a string wont work.  So I need to find what slide has this string as a label so I can find its number

By loop, I mean a Javascript "for" loop --> for (var i=0; slides.length; i++) {if(slides.label=="4 Content") var slideNumber=slides.slideNumber}, something like this...  I just want to somehow find the slide with "4 Content" as a slide name so that I can jump to it.

Lilybiri
Legend
July 7, 2016

That first number is the slide number, must miss something but you cannot have '4 Intro' and '4 Content' in the same file? Slide 4 will have one name, it is possible that another slide has the same name (bad practice) but never the same number.