Random Team Generator?

  • Adobe Edge Animate - April 19, 2016

This code snippet lets you specify 4 different teams, then randomly generate 2 matches as if it where a semi-final draw. By clicking a button the draw can be made over and over again.


First create a symbol on the stage called 'Teams' and inside that symbol create a text layer and call it 'TeamName'.

Back on the stage duplicate the 'Teams' symbol four times and rename them on your timelines as Team1, Team2, Team3, Team4

Now create a button on the stage and put the following code on button click:

var numberOrder = []
while(numberOrder.length < 4){
  var randomnumber=Math.ceil(Math.random()*4)
  var found=false;
  for(var i=0;i<numberOrder.length;i++){
  if(numberOrder[i]==randomnumber){found=true;break}
  }
  if(!found)numberOrder[numberOrder.length]=randomnumber;
}
 
Team1 = sym.getVariable("Team"+numberOrder[0]);
Team2 = sym.getVariable("Team"+numberOrder[1]);
Team3 = sym.getVariable("Team"+numberOrder[2]);
Team4 = sym.getVariable("Team"+numberOrder[3]);
 
sym.getSymbol("Team1").$("TeamName").html(Team1);
sym.getSymbol("Team2").$("TeamName").html(Team2);
sym.getSymbol("Team3").$("TeamName").html(Team3);
sym.getSymbol("Team4").$("TeamName").html(Team4);

Finaly you need to set a list of variables with the team names that you need, in document.compositionReady put the following code:

sym.setVariable("Team1", "Team 1 Name");
sym.setVariable("Team2", "Team 2 Name");
sym.setVariable("Team3", "Team 3 Name");
sym.setVariable("Team4", "Team 4 Name");

 

Comments