0
Use a variable from another symbol HTML5
New Here
,
/t5/animate-discussions/use-a-variable-from-another-symbol-html5/td-p/11527450
Oct 21, 2020
Oct 21, 2020
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/animate-discussions/use-a-variable-from-another-symbol-html5/m-p/11528235#M336451
Oct 21, 2020
Oct 21, 2020
Copy link to clipboard
Copied
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;
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

