Game Development Reference
Runtime errors happen when the code looks for something that it can't find while the program is run-
ning. There's a very good reason for why this runtime error occurs: dependency .
The error tells you that the S]hh class is looking for a method called _da_g?khheoekjSepdLh]uan and can't
find it. Just to refresh your memory, this is the directive in the S]hh class that looks for that method:
It's looking for this method in the l]najp object: `qjcakjKja. `qjcakjKja contains the @qjcakjKja[I]j]can
class. When the game switched levels, it removed `qjcakjKja. The @qjcakjKja[I]j]can class is bound to
`qjcakjKja, so it was also removed. The walls are all looking for the _da_g?khheoekjSepdLh]uan method
in the @qjcakjKja[I]j]can class and, of course, can't find it.
The S]hh class depends on the _da_g?khheoekjSepdLh]uan method. This is not a good thing!
At this stage in your learning, using dependencies like this helps you understand how classes commu-
nicate and allows you to achieve a complex technique such as multiple object collision with minimal
code. In Chapter 10, I'll show you how you can use events to avoid this.
For now however, dependency is isn't too bad if you manage it carefully. There are a few ways you can
solve the runtime error you received:
1. Create a class called @qjcakjPsk[I]j]can and bind it to the @qjcakjPsk symbol. Make sure
that it contains a method called _da_g?khheoekjSepdLh]uan* The wall objects in @qjcakjPsk
still look for the parent object, but they then find the code they're looking for in @qjcakjPsk[
I]j]can* As long as the name of the method hasn't changed, it works. If you'll create a second
level of the game, you'll need a @qjcakjPsk[I]j]can class anyway, so this solution makes
2. Create a third class, maybe called ?khheoekj[I]j]can, that isn't bound to any objects and is
just used for checking collisions in the game. Game objects send references of themselves to
this new class. The next section makes one suggestion about how to do this.
This is just a very general description to get you thinking about the problem of code dependency.
When you design your classes, avoid any code that depends on other classes if you can. It's impossible
to completely remove dependency from your games and programs, but with careful planning you can
minimize its impact.
If you get a runtime error in any of your games, you can find out where the problem is
by selecting Debug ° Debug Movie . Flash's debugger starts its work and points to the
line in your code where the error is. You still have to figure out exactly why the error is
occurring, but as least you know where to start looking.