Game Development Reference
In-Depth Information
Creating custom error classes is even more straightforward than
custom event classes, so I
ll give only a brief example of how to do
so. I have found that the basic included error types are more than
enough to handle the errors I need to create. Here is a quick exam-
ple of a GameError class that you could use to hold a number of
predefined error messages.
package {
public class GameError extends Error {
static public const INVALID_INPUT:String = " That is
not a valid form of input for this game. " ;
static public const GAME_NOT_READY:String = " The game
object is not yet initialized. Run init() before
starting game. " ;
public function GameError(message:String=
public function startGame():void {
if (!initialized) throw new GameError(GameError.
In this example, the GameError class (much like an Event
subclass) predefines the error messages the game will use for easy
access and syntax checking. If the game is not initialized when start-
Game is called, it will throw a GAME_NOT_READY error. For more
information about error handling, check out the online chapter
Em If You
ve Got
available on the topic
Part 4: Data Structures and Lists
One of the most important abilities in programming is being able
to group similar objects together in lists for easier tracking. For
example, a game might have a player, a number of different kinds of
enemies, and a number of pickup items. It is inefficient, or even
impossible in some scenarios, to keep track of the enemies and pick-
ups with individual variables, so we need more complex data struc-
tures to store them and make them easily accessible. AS3 gives us
four main containers for this type of data, and depending on what
type of information you
look at each of these structures, their pros and cons, the best tasks
for them, and how to iterate , or step through, each of them.
re trying to store, a fifth one as well. We
Search Nedrilad ::

Custom Search