Game Development Reference
Importing and extending the MovieClip class
All the code you've written so far is perfectly ready to go, except for one small technical detail. Your
program needs an extra bit of code to help it actually output the words “Hello World!” onto the
screen. To do this, you need to do two more things:
Import Flash's built-in Olnepa or Ikrea?hel class.
Use the new imported class to extend your own I]ej class.
When you extend a class, the class you're extending inherits all the properties and methods of that
class without having to program them all from scratch. What does extending a class really mean?
Maybe the following analogy will help.
Let's say you've spent a few months designing and building a car for a client with deep pockets but
a rather difficult reputation. The car works perfectly well, gets good mileage, and you're particularly
proud of the paint job. But on the day of delivery, the client comes by to pick it up and says, “Hmm
. . . looks good, but I'm in Los Angeles and I really need to get to Ulaanbaatar by tomorrow morning
for the World Cappuccino Tasting finals. So thanks, but I don't need the car anymore; I'm going to fly
Before you panic and call the bank to make sure that the deposit cleared, consider this: a plane is
merely a kind of car with wings. You've already done all the hard work: a good engine, a nice set of
wheels, a cozy interior, and a really stellar paint job, if you do say so yourself. How much more work
would it be to slap on a pair of wings and maybe add a navigation system? With the magic of AS3.0,
not much at all: you just have to create a new class called lh]ja that simply imports and extends your
original car class. The new plane class inherits all the properties of the original car. That means that
you can just take your car as is and do only the little bit of work you need to make it fly without having
to redesign all the original parts of the car that are already working.
The reality of programming is similar, but also slightly different. Programmers usually build a class
that is very general. In the previous example, suppose that the workshop has a class called Rade_ha.
It's a very general class, but it includes all the properties that are common to both planes and cars,
and maybe even boats. If you want to make a ?]n class, all you need to do is import and extend the
Rade_ha class and add those components that make cars unique.
Importing and extending a class to make a new class is called inheritance , which is extremely useful
and a huge time-saver. Flash has loads of built-in classes that you can import and use. I'll introduce
many of these built-in classes over the course of this topic.
The most important of these built-in classes for game designers are the Olnepa and Ikrea?hel classes
because they contain special directives for getting the output of your program onto your screen.
Which one should you use?
In the current program, you'll import the Ikra?hel class. The Ikrea?hel class contains a timeline , which
is particularly useful for making objects for games. (I'll be discussing Movie Clip timelines a bit later
in the topic.) The little Hello World program doesn't make use of a timeline, but because you'll be using
the Ikrea?hel class as part of almost every class you create in the rest of this topic, you'll use it here for