Forum Discussion

HoneyTurner's avatar
HoneyTurner
Community Member
4 days ago
Solved

Capturing Text from a Shape or TextBox

I have a game with 40 questions, subdivided into 4 categories. I've created an object for each category and used states for each question within the category. My current plan is to enter the questions in the WYSIWYG environment for easier proof reading than if I tried to enter them into the Variables editor.

It's a team based game and if nobody can get the answer right, I want it to save the question to a variable, then at the end of the game, I want it to email the questions to the SMEs.

My problem is that unless I switch to using 40 variables, I haven't figured out a way to pull the question from the object before moving on to the next question. 

I had thought it would be something simple like this:

const jsObject = object('6N5bhivlzyV');

set jsText = jsObject.value;

setVar('theText',jsText);

But, that's not working. Is my javascript bad or is there a way to do this with standard triggers?

  • I am confused by your setup description, but I suspect that you expect the text within a slide shape to be contained in the object's value property. Text in a Storyline object, especially formatted text, is generally embedded into an SVG element, broken down into text groups based on the formatting applied. You could extract the text, but not simply. The text is also represented in a hidden part of the page called the shadow-DOM.  If, for example, you had a button with a text label of "Press Me", and the object was defined by

    const button_1 = object("6UNtrp5jRD9")

    you could potentially extract the text value by identifying the corresponding button element in the shadow-DOM, and then accessing the innerText property. For example:

    // Use the object ID as identified by Storyline, and append 'acc-' to the beginning to obtain the element's ID in the shadow-DOM.
    
    let buttonText = document.getElementById("acc-" + "6UNtrp5jRD9").innerText
    
    //This would return the value 'Press Me' to the variable buttonText

     

3 Replies

  • I am confused by your setup description, but I suspect that you expect the text within a slide shape to be contained in the object's value property. Text in a Storyline object, especially formatted text, is generally embedded into an SVG element, broken down into text groups based on the formatting applied. You could extract the text, but not simply. The text is also represented in a hidden part of the page called the shadow-DOM.  If, for example, you had a button with a text label of "Press Me", and the object was defined by

    const button_1 = object("6UNtrp5jRD9")

    you could potentially extract the text value by identifying the corresponding button element in the shadow-DOM, and then accessing the innerText property. For example:

    // Use the object ID as identified by Storyline, and append 'acc-' to the beginning to obtain the element's ID in the shadow-DOM.
    
    let buttonText = document.getElementById("acc-" + "6UNtrp5jRD9").innerText
    
    //This would return the value 'Press Me' to the variable buttonText

     

    • HoneyTurner's avatar
      HoneyTurner
      Community Member

      Thank you! I had tried variations with and without acc- but what I hadn't tried was innerText. That was the winner. It now does exactly what I wanted it to do.

      • HoneyTurner's avatar
        HoneyTurner
        Community Member

        For anyone trying this out themselves, it did not work if I attached the javascript to "when timeline starts on layer". But it did work "when variable changes" or "when button clicked".