Graphics Reference
In-Depth Information
var cardObj:Object = e.currentTarget;
cardObj.buttonMode = false;
cardObj.getChildAt(1).visible = false;
_cardsToCompare.push({bitmap:cardObj.getChildAt(0).bitmapData,
card:cardObj});
if(_cardsToCompare.length == 2){
if(_cardsToCompare[0].bitmap.compare(_cardsToCompare[1].
bitmap) == 0){
dispatchEvent(new
MemoryGameEvent(MemoryGameEvent.CORRECT_MATCH));
correctMatch();
}else{
dispatchEvent(new
MemoryGameEvent(MemoryGameEvent.INCORRECT_MATCH));
_allowClick = false;
setTimeout(hideCards,1000);
}
}
}
// hideCards hides the cards if they are not a
match
private function hideCards():void{
for(var c:int=0; c < _cardsToCompare.length;
c++){
_cardsToCompare[c].card.getChildAt(1).visible = true;
_cardsToCompare[c].card.buttonMode = true;
}
_cardsToCompare.splice(0);
_allowClick = true;
}
/* correctMatch adds to the number of total matches
found and, if all matches
have been found, dispatches a custom event of
" GameComplete " */
private function correctMatch():void{
_matchesComplete++;
_cardsToCompare.splice(0);
if(_matchesComplete == _numberOfCards/2){
dispatchEvent(new
MemoryGameEvent(MemoryGameEvent.GAME_COMPLETE));
}
}
}
}
Search WWH ::




Custom Search