Game Development Reference
In-Depth Information
Custom Events
If you find during development that you need an event type that
contains more information than a generic event, you can easily
extend the Event class to make custom events. Let
'
s look at one
quick example:
package {
import flash.events.Event;
public class GameEvent extends Event{
static public const GAME_START:String = " gameStart " ;
static public const GAME_WIN:String = " gameWin " ;
static public const GAME_LOSE:String = " gameLose " ;
public var score:Number;
public var timeLeft:Number;
public var level:int;
public var difficulty:int;
public function GameEvent(type:String,
score:Number = 0,
timeLeft:Number = 0,
level:int = 1,
difficulty:int = 1,
bubbles:Boolean = false,
cancelable:Boolean = false) {
this.score = score;
this.timeLeft = timeLeft;
this.level = level;
this.difficulty = difficulty;
super(type, bubbles, cancelable);
}
override public function clone():Event {
return new GameEvent(type, score, timeLeft, level,
difficulty, bubbles, cancelable);
}
}
}
ve created a custom event class, it makes more sense
to keep the event type names here, rather than in the Game class.
In this case, GAME_OVER has been split into GAME_WIN and
GAME_LOSE for more specific events. Also, we
Since we
'
'
ve included holder
variables for the game
s current score, time left, difficulty, and
current level if they were applicable. Obviously, you would tailor
'
Search Nedrilad ::




Custom Search