Game Development Reference
In-Depth Information
Firing bullets
The Sa]lkj and >qhhap classes work together to fire bullets. When the player presses the spacebar,
the Sa]lkj class's odkkp>qhhap method is called:
If [sa]lkj=nia` is pnqa, the directive that creates the bullets is run:
This adds a new instance of the >qhhap class to the l]najp container of the Sa]lkj class: `qjcakjKja.
The ^qhhap object is created without an instance name .
This is the first time you've seen an object created without an instance name. The format for creating
objects that you're more familiar with is this one:
With this format, you can use ^qhhap to refer to the bullet object you just created. With the for-
mat used in the Sa]lkj class, the object is created but it isn't given a name. If these objects aren't
assigned instance names, what happens to them when they're added to `qjcakjKja? They actually
have instance names, but these names are assigned automatically by AS3.0. That's just fine because
you don't need to reference any of the bullet objects specifically in the code.
If you want to find out the instance names to which AS3.0 assigns the bullets, drop this
directive into the >qhhap class's kj=``a`PkOp]ca event handler:
When you start firing bullets, you'll see something like this in the Output panel:
AS3.0 assigns these names automatically. Interesting!
Figure 8-23 illustrates how the Sa]lkj class fires bullets.
Search Nedrilad ::

Custom Search