Execute JavaScript - passing object to script?

Aug 06, 2021

Hi,

Does the Execute JavaScript pass the object which executed the script, to the script in any way?

I'm trying to get hold of the object in JavaScript which calls the script in a easy way so if anyone knows of a way, please let me know!

Thanks,
PJ

12 Replies
Walt Hamilton

You can set a variable in SL, and Get it in js.

For example, Adjust variable CallingObject set value = slide6button 1 when user clicks Button 1.

Execute js when user clicks Button 1. 

Then js Gets CallingObject.

Seems pretty easy to me. After all, you have to create the trigger to execute the script, and the js is going to have the code to handle  whatever calls it. All you have to do is to add the trigger to set the variable.

Zsolt Olah

I'm not sure what exactly you mean by "object." The script you put in a JS trigger gets wrapped in a function and then executed from the user.js file based on the conditions and timing of the trigger. You can pass a variable using GetPlayer().GetVar() or set the SL variables using GetPlayer().SetVar(). Beyond that, you can't do too much. The only object you can interact with is the player. 

AVT Connect

Ah thanks for the replies. I was hoping that the object triggering the script would be passed down to the user.js as a DOM object which would allow for easy manipulation in JavaScript. But I did find this, which helped me to get around it: https://community.articulate.com/discussions/articulate-storyline/gsap-3-5-1-latest-version-is-now-included-in-storyline-360

Math Notermans

As this post triggered me to see if i can find a way to get info of a clicked element with the help of Gsap in Storyline...i did.

Basically with this line of code you can get the active focused element in the DOM.

var activeEl = document.activeElement;

With the help of the 'getProperty' function of GSAP you then can get any info you want from that element.

var accName = gsap.getProperty(activeEl,"data-acc-text");

Then its easy to manipulate or get info from your document with GSAP.
If you want any other element on your page acting upon a specific buttonclick you can use the z-index to target any visible element in your Storyline.

var elZindex = gsap.getProperty(activeEl, "z-index");

All elements in your timeline are on a specific z-index. The lowest is 1, numbering up.

Making a separate post showing it working...