Adobe Edge Animate

Adobe Edge variables, counting coins [EN]

To create an interactive environment in Edge Animate, we need to have some code. And one of the most important things are variables. To declare a variable, select your stage and click on “open actions” button near the title of your project (properties). Select “creationComplete” and add all the following code below:

sym.setVariable("varName", 0);

Where “varName” is your variable name. The number behind that is the start value of this variable.

When you have a coin you can collect, select the coin symbol and click on “open actions” in the properties window.
Add the following code:

// lets get the variable "varName" and put it into another variable named "Name"
var Name = sym.getVariable("varName");
// this is the important part, counting. Add 1 to the value of the variable "Name"
Name = Name + 1;

This code gets the variable name varName and puts it in a new var “Name”. After that we add a plus 1 to this variable, so we know that someone has clicked on the coin and that we can keep track of it.

sym.setVariable("varName", Name);

We want to keep counting, so we have to put the 1 back in our global variable. After that we want to show the variable in a textfield. This textfield has an id “TextField”.

// when you have clicked on the coin, make it disappear with a fadeout
// if we have clicked on 3 coins, show a symbol.
if (Name ==3){

When the user has clicked on the coin, it has to disappear. That’s where we use the “fadeOut” function. The number between the brackets is how long the fade can take.

If the user has clicked on 3 coins, we want to show a symbol. So that’s where the check if the varName is 3 comes into place. Use the same code for the other 2 coins and be sure to use other id’s for the coins.

This is one way to do this, there could be others. If you have another way to do the same, please let me know.

Een gedachte over “Adobe Edge variables, counting coins [EN]

  • Another way to do this is:

    This code has to be placed on the stage. Important is that every coin has a “class name”, coin. At the properties, in the top right you will find a button with a “s”.

    // insert code to be run when the symbol is created here
    var numberofCoins = 0;

    //when the user clicks on a coin (class has to be coin)
    $(“.coin”).click( function (){

    //this says it has to remove the clicked coin

    //numberofCoins++ ads 1 to the variable

    //with sym. we call on a unique element. Text places the var in a textfield
    //testing if numberofCoins is 3
    if (numberofCoins == 3){
    //if it’s true show the congrats screen, hide for hiding

Geef een reactie