Game Development Reference
The =@@A@[PK[OP=CA event has a companion event called NAIKRA@[BNKI[OP=CA. The NAIKRA@[BNKI[OP=CA
event fires when an object is “removed from the stage.” This is very useful in a game because objects
(like enemies who are hit by bullets) are frequently removed. It allows the object to perform some final
tasks, such as updating a score or spawning a new object just before they flicker out of existence.
Also, very importantly, the NAIKRA@[BNKI[OP=CA event allows you to remove any event listeners that
might be attached to the object. This is particularly important for AJPAN[BN=IA events. One of AS3.0's
little quirks is that even after objects are taken off the stage using naikra?deh`, their AJPAN[BN=IA
events will still run silently in the background. If an AJPAN[BN=IA event is running and trying to reference
objects that no longer exist, it will generate a torrent of error messages in Flash's Compile Errors pane.
To prevent this, you can use the NAIKRA@[BNKI[OP=CA event to remove the object's kjAjpanBn]ia event
listener when the object itself is removed.
Although manually removing AJPAN[BN=IA events is required, removing other event
listeners manually is optional. Flash still deletes objects even if they have listeners on
in most cases. However, just to make sure, it's considered best practice to manually
remove them so you know with absolute certainty that that there won't be any linger-
ing code running in the background after the object is gone.
In Dungeon Maze Adventure, I used =@@A@[PK[OP=CA and NAIKRA@[BNKI[OP=CA with all the classes.
Using them together is a bulletproof way to make sure that objects initialize properly and don't leave
lingering code running in the background when they're removed. Here's the format that all the classes
in Dungeon Maze Adventure use: