Time for action – ID the cards
Let's revisit our card-creation code and give each card an ID number. We'll use that number to detect matches.
In the
BuildDeck
function, add this line:function BuildDeck() { var totalRobots:int = 4; // we've got four robots to work with var card:Object; // this stores a reference to a card var id:int = 0;
Look a little further down the code. Pass the
id
value to theCard
class with each robot and missing body part card, and then increment the ID number:card = new Card("robot" + (i+1) + "Missing" + theMissingPart, id); aCards.Add(card); card= new Card("robot" + (i+1) + theMissingPart, id); aCards.Add(card); id++;
Add
id
as a property of theCard
class. Acceptid
as an argument in theCard
class constructor function, and set the card'sid
instance variable to that value:class Card extends System.Object { var isFaceUp:boolean = false; var isMatched:boolean = false; var img:String; ...