Adobe Edge Animate and variables, a bouncing ball [EN]

On stage we want a ball, two buttons and a textfield. The ball can roll and bounce. The two buttons make the ball roll or bounce. The textfield is to show in text what button is clicked, if the ball is rolling or bouncing.

Screen Shot 2014-09-26 at 14.49.21
The stage, two buttons, a symbol with animation inside and a textfield.

Make a circle on stage and convert it to a symbol. In the ball symbol you would have two animations, one where the ball rolls and one where it bounces. Be sure to put the labels at the right point in time by going to where you want to have the label and click on the insert label button.

Screen Shot 2014-09-26 at 14.55.02Just before the second label i have placed a stop function (the little symbol underneath the “insert label” button and make sure your playhead is at the right position):

sym.stop(0);
the timeline inside the ball symbol

To have the symbol react to different variables, use the following code for clicking on the “roll the ball” button (select the button and in properties, click on “open actions” and select “click”):

// set the variable varName with the value "roll"
sym.setVariable("varName", "roll");
 
//get value variable
var myVarName = sym.getVariable("varName")
 
// change text in element with id textField and play the symbol "ball" from label "roll" 
sym.$("textField").html(myVarName);
sym.getSymbol("ball").play("roll");

To make the ball bounce by clicking on the “bounce the ball” button (select the button and in properties, click on “open actions” and select “click”):

// set the variable varName with the value "bounce"
sym.setVariable("varName", "bounce");
 
//get value variable
var myVarName = sym.getVariable("varName")
 
// change text in element with id textField and play the symbol "ball" from label "bounce" 
sym.$("textField").html(myVarName);
sym.getSymbol("ball").play("bounce");

If you find a better solution for doing this, please let me know.

Adobe Edge Animate and variables, collect 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);
sym.$("TextField").html(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
sym.$("coin").fadeOut(200);
 
// if we have clicked on 3 coins, show a symbol.
if (Name ==3){
sym.$("CongratsSymbol").show();
}

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.