Forum Discussion

BartVandenBr275's avatar
BartVandenBr275
Community Member
7 months ago

Javascript events in Storyline

Hi all,

I am trying to send a custom javascript event from an embedded storyline web object to storyline. I would like to listen for this event in a javascript trigger.

However, I am unable to hear my dispatched event.
Is there anyone with some javascript knowledge or a dev who can help me out?

The thing is, I AM able to listen for standard events like localstorage changes but it would be much easier if I could skip storing a variable in localstorage.

Anyway, I would appreciate some help as I have been searching the whole day :D

  • Hi Bart,

    One way you can get Storyline to react to an event from JavaScript in a WebObject is to change a variable value in your Storyline file.

    You could have a variable called "listener" (type text) in Storyline. You can then update the value of this variable from your WebObject:

    // Get reference to storyline player
    // using parent, as a WebObject is in an iframe
    const player = parent.GetPlayer();
    player.SetVar("listener", "dosomething");


    Then in Storyline, you can set-up a trigger that reacts when the variable "listener" is changed, for example:

    Jump to slide next slide
    When the variable changes
    listener

    If listener = value "nextslide"

    One thing to look out for though, is sending multiple "nextslide" values to the variable will not trigger a change, as it is the same value. You would always have to set your variable back to "(blank)" to ensure that each event, is a variable value change.

    Will that help with your situation Bart?

  • Hi Sam,

    Thanks for the tip about getting the player from the parent.
    I will test this.

    Kind regards,
    Bart

  • Hello all,

    I am trying to execute javascript in a virtual tour created with 3D Vista. The hotspot runs the following code:

    const player = parent.GetPlayer();
    player.SetVar("test", "1");

    Then export the tour and embed into Storyline as a web object. I created a var named "test" with 0 as starting value, and a trigger to jump to the next slide if the variable "test" changes to 1.

    And lastly, I publish the storyline in review360... but can't jump to the following slide clicking the hotspot. Could anyone help me? Not sure what I am doing wrong...

    Thank you! 

  • Running the code with the hotspot alone will not work. If you want to change the variable value by clicking the hotspot and not from the Web Object, you should avoid using 'parent'. If you want to change the variable from within the Web Object, you should attach your original code to the appropriate event. For instance, when a virtual tour is complete or when a specific action occurs during the tour.