Game Development Reference
In-Depth Information
these properties to your specific game. In the Game class, we
would now dispatch events like the following:
dispatchEvent(new GameEvent(GameEvent.GAME_START));
Thereareacoupleofthingstorememberwhenextendingthe
Event class. One is that any additional properties you want to store
must have variables created for them, so the constructor can assign
them or they can be re-assigned after the event object is created.
Another point to keep in mind is that you need to explicitly call the
Event superclass constructor through super() and pass it at least
the first parameter (and preferably all of them). The final aspect of
events to remember is that you should provide a clone method to
override the original. The clone method is automatically used by
Flash when events are re-dispatched from a listener object. If an
override is not provided, it will return a generic event rather than
your custom type. While it is not mandatory to provide it, it is a
best practice and will prevent problems from cropping up down
the road where your data gets lost along the way.
That completes this section on events. While there are even
more aspects of the event model in Flash which we could explore,
what we
ve learned represents the core functionality that you will
likely use when developing games.
'
Part 3: Errors
No one likes errors in their code. In fact, no one likes their
mistakes being pointed out by others, let alone a computer. It
may sound like an absurd statement, but errors in Flash really are
your friends. In ActionScripts 1 and 2, errors were passive
if
they occurred, things might break, but you wouldn
t necessarily
know where or why. When I first switched to AS3, I couldn
'
'
t
stand how many errors I got and it drove me nuts. Now that I
'
ve
gotten used to it, I
m very appreciative when Flash presents me
with a batch of errors; I would much rather know that something
happened and be able to fix it rather than have it fail silently and
have no idea why my application isn
'
t running as expected. And
really, though my ego might not like to admit it, those errors
were probably in my AS1 and AS2 codes; I just didn
'
tknowit.As
some of you may already know, errors in ActionScript 3 make
themselves known by bringing your program (or at least method)
toascreechinghaltanddisplayingamessageintheoutputwin-
dow. Anyone first developing in AS3 is bound to cause quite a
few errors. You
'
ll also note quickly that the Flash documentation
tends to refer to them in a couple of different ways. Sometimes
errors are referred to as exceptions .Also,becauseerrorsare
derived from the Error class, there are a number of subclasses
'
Search Nedrilad ::




Custom Search