Game Development Reference
Methods? Of course you know what methods are by now! Here are the giraffe's methods:
By using properties and methods together, you can create a model of an object. If you understand that,
that's what 50% of what object-oriented programming is all about. The other 50% is coming up next.
Private properties and methods
In the previous code the properties and methods were declared as lner]pa:
Private means that those properties and methods can be used only within the class they're defined.
They can be used in the Cen]bba class and nowhere else. No other class (an Ahald]jp class, for exam-
ple) can stick its nose into the giraffe's business and find out whether or not it was hungry or what its
favorite activity is. Those matters are entirely private.
If you don't use the lner]pa keyword when you declare a property or method, AS3.0
assumes that they're public. Public properties can be accessed freely by any other classes.
You can use the lq^he_ keyword to make this explicit in your code if you need to.
Why should you declare a property as private? Imagine that your house is a class, and your oven is
one of the class's properties. Your oven is having trouble switching on, so you call a repairman to take
a look at it. But you're really busy and can't be home when the repairman comes, so you leave the
door unlocked and trust that all will be well. Best-case scenario: you come home to find that your
oven works, but a vase is lying broken on the floor, an empty pizza box is on the sofa, and a bill arrives
at the end of the month for all kinds of pay-per-view movies you know you never watched. Worst-case
scenario: you come home to find your house a smoldering ruin and all the other houses in the neigh-
borhood up in flames. If only you could have been there to tell the repairman (who was standing
ready with his 10,000-volt charge-jumper), “It's a gas stove, not electric!”
In a very small game with only a few classes, you could probably get away with directly accessing
another class's public properties and methods. In a larger game, however, you'd be opening yourself
up to a potential debugging nightmare scenario. So, except for a few exceptions that you'll be looking