Graphics Reference
In-Depth Information
The MemoryGameEvent Class
Each time a user turns over two cards in the memory game, the
game needs to know if the two cards match or not. That
swhere
the MemoryGameEvent class comes in. The MemoryGameEvent
class extends Event and is pretty specific to the memory game
since the events it dispatches are directly related to matching cards
and completing a game.
'
MemoryGameEvent Code
package com.flashadbook.events{
import flash.events.Event;
import flash.events.EventDispatcher;
public class MemoryGameEvent extends Event{
public static const INCORRECT_MATCH:String =
" incorrectMatch " ;
public static const CORRECT_MATCH:String =
" correctMatch " ;
public static const GAME_COMPLETE:String =
" gameComplete " ;
public function MemoryGameEvent(type:String,
bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
}
public override function clone():Event{
return new MemoryGameEvent(type, bubbles,
cancelable);
}
}
}
MemoryGameEvent Breakdown
Once again, the package for this class mirrors that of the class it
extends. In this case, MemoryGameEvent is in the com.flashad-
book.events package. Since it does extend Event and we want it to
behave as an Event would, the first thing we do is import flash.
events.Event and flash.events.EventDispatcher . The next items in
MemoryGameEvent are the constants that represent the events that
can be dispatched. They are pretty self-explanatory in their names:
CORRECT_MATCH , INCORRECT_MATCH ,and GAME_COMPLETE .I
msureyou
can guess what each one represents. The only two things left in
this class are the standard Event constructor and the overridden
clone function.
'
Search WWH ::




Custom Search