Skip to main content
Participant
October 21, 2020
Question

Use a variable from another symbol HTML5

  • October 21, 2020
  • 1 reply
  • 182 views
How to do to be able to use a variable that is inside a symbol in another symbol?
What I want to do is count points in a symbol, when changing symbols I want it to keep the same score.

var count = 0;
this.total.text = count;

keep that value and use it in the next symbol.


    This topic has been closed for replies.

    1 reply

    Legend
    October 22, 2020

    It's (usually) impossible to externally access variables declared with var in a symbol's code, because they cease to exist after the code finishes executing. To make a variable persistent and externally accessible, you have to make it a property of the symbol:

    this.count = 0;

     

    But this is probably the wrong approach anyway. It sounds like it would be more appropriate to just make the count globally accessible by storing it on the root object, exportRoot:

    exportRoot.count = 0;