Global Variables

  • Adobe Edge Animate - March 1, 2016

If you have ever needed to access a variable from within a symbol and in addition change its value, then you need to make your variables global.

A 'global variable' is a variable that it can accessed and reset throughout your project from within any symbol at any level in your project.


The following code explains simply how this process works, in your document.compositionReady put the following code:

sym.setVariable("myGlobalVariable", false);

The above creates a new global variable called myGlobalVariable and sets the value to false.

Now, from within any symbol when you need to access this variable, type the following code:

sym.getComposition().getStage().getVariable("myGlobalVariable");

This gets the global variable for you to use however you please. Lets say that you now want to set a local variable from within a symbol by refrencing the global one, just use the following:

var mylocalVariable = sym.getComposition().getStage().getVariable("myGlobalVariable");

Finally you can also reset the global variable from with a symbol to a different value by using the following:

sym.getComposition().getStage().setVariable("myGlobalVariable", true);

This sets the value of the global variable myGlobalVariable to true.

Download Files

Comments