JavaScript, Passing and Using Variables
Mar 19, 2014
Hi Guys,
Having a small problem with executing JS in our Storyline files. Basically i am trying do a toggle function for turning a Close Caption screen on and off for our users (which Storyline doesn't seem to have functionally for).
So what i have currently is a project file with the following:
Variable named "ccCount"
Layer named "CC"
a Trigger stating:
Show Layer "CC" when timeline starts, if ccCount = 1
a Trigger stating:
Hide Layer "CC" when timeline starts, if ccCount = 0
Here is the JS:
var p = GetPlayer();
var ccOn=1;
var ccOff= 0;
var cc = p.GetVar(“ccCount″)
if (cc = 1)
{
p.SetVar("cc", ccOff);
}
else
{
p.SetVar("cc", ccOn);
}
I am executing that JS from a button added to the player (like adding an Exit button to it). The JS doesn't seem to work through this or on a button added to the content, is it my JS that's wrong? I cant even get one button to Trigger like a toggle button (i guess you can do that with a state change, but i want to move this functionally to the player, so i don't have to copy and paste the button into every slide and keep it out of the content). any help would be appreciated with this.
4 Replies
Hi Keith
I'm not a javascript expert, in anyway shape or form, but I've managed to create what I think you want without using it.
I've got a slide with a closed caption layer that is controlled by a true/false variable. The variable starts False and when the user click the button to open the captions it also adjusts the variable to True. If the user then closes the captions it also resets the variable to False.
Adding a trigger to the timeline of the slide to open the caption layer if the variable is True means that if the user moves on with the captions open they will remain open when they return to this slide, if they close the captions before moving on the slide reopens with the captions closed.
Hope this is what you were wanting to do and that it might simplify things for you, just bear in mind you need a new variable for each slide that contains captions.
Cheers
Helen
Hi Helen,
Thank you for your reply, I will have a look at your example and see if it is something we can use. We do however want to avoid the having a CC button in the course content. I will adding a working file to this post tomorrow, as I have to separate it up from our IP first.
Keith
Keith, Have a look at the attached file and here is the published version. I fixed a few things in your script. Also, I added a couple of triggers per slide that not only toggle the CC Layer when the timeline starts, but immediately when the variable changes. Hope that helps.
Hi Michael
Thank you very much! I shall have a look at that and integrate it in today!, I had just put a file my self outlining what I had achieved and where we were heading with it,
Hopefully our designer will be happy with this, i'll let you know how we get on.
Keith
This discussion is closed. You can start a new discussion or contact Articulate Support.