Game Development Reference
In-Depth Information
In Chapter 7, you looked at how to use a static method in an external class called ?khheoekj. This was
helpful because you could keep the rather complex collision code from getting tangled up with the
main part of the program. It made your program much easier to read, but you could still use the col-
lision code whenever you wanted to with just one simple directive.
In this chapter, you'll go one step farther: all the important objects in the game will be programmed
in their own classes. You'll also see how to use a special manager class to coordinate the behavior of
these objects.
Introducing object-oriented programming
Before you get to the case study at the heart of this chapter, you'll take a quick break from program-
ming to look at some basic object-oriented programming techniques and concepts:
Binding classes to symbols
Using properties and methods
Using private properties and encapsulation
Communicating between classes using getters and setters
There are some new concepts to grasp in the pages ahead, but you'll soon see how easy it all is to put
into practice.
Binding classes to symbols
It's possible to create a symbol in the Library and then bind it to a class. The class is a self-contained
file that contains the programming code to control all instances of that symbol.
Here's how it's done. Remember that when you create a new symbol, the Create New Symbol dialog
box allows you to select Export for ActionScript as an option in the Linkage section. The Class field
allows you to provide the name of the class that you want to link to that symbol. It automatically sup-
plies the symbol name as the class name.
What this means is that whenever you use an instance of the symbol in your game, the class file that
you supplied in the Class field is automatically loaded and attached to the object. Figure 8-1 shows an
example. If your symbol is called Cen]bba and you also used the class name Cen]bba, Flash will look
for a class file called Cen]bba*]o and attach whatever programming code it contains to any cen]bba
objects on the stage.
Figure 8-1. Flash looks for a file called Giraffe.as if you specify Giraffe as the
class name.
 
Search Nedrilad ::




Custom Search