Game Development Reference
`qjcakjKja is a Movie Clip object. Sometimes AS3.0's compiler needs your help to tell it exactly what
kind of thing an object is. You need to force it to interpret l]najp as a Movie Clip object by using the
previous format. This procedure is called type casting .
If you ever need to access the document class directly from any other class, you can
It allows you to access the main timeline, the main stage, any objects on the main
stage, and properties of the document class.
By using Ikrea?hel$l]najp% to refer to `qjcakjKja, you can actually access any object in the game
from within the >qhhap class like this:
If you ever need to refer to an object in a parent container, use this format.
As useful as this technique is, it's actually not a good idea to use it too often in your
own projects. It makes the class completely dependent on instances inside another
class. If those instance names change or the object no longer exists, the code won't
work. This is known as tight coupling and it breaks a class's encapsulation. As a gen-
eral rule, try not to program your classes so that they refer to specific objects inside
other classes. It will be harder for you to debug and change your game if you do. I've
done so here as an example of how to do it if you need to, but in later chapters the
code will avoid this.
Of course, the most important thing the bullets do is help the player defeat the enemies. Let's look at
how this works next.
Bullets vs. enemy collisions
The >qhhap class and the @qjcakjKja[I]j]can class work together to check whether the bullets are
hitting the enemies.
First, the bullet objects need to tell @qjcakjKja[I]j]can that they exist. One directive in the >qhhap
class does this:
It might look confusing at first glance, but don't let it scare you. In plain English, it reads as follows: