Game Development Reference
Part 6: Why Does Flash Do That?
Event Flow 68
Frame Scripts 69
Working with Multiple SWF Files
In this chapter, we
ll cover best practices to use when program-
ming in ActionScript 3. This includes smart class utilization, using
the event model, error handling, and data structures. We
cover a number of idiosyncrasies of Flash, which tend to trip up
developers coming to Flash from other languages.
s worth mentioning that this chapter (like the rest of this topic)
assumes a familiarity with either ActionScript 1 or 2 or another
programming language. If you have no idea what objects, variables,
or functions are or have never used Flash at all, you will be lost
very quickly. Some familiarity with ActionScript 3 is ideal since
ll also be moving pretty quickly through a wide variety of topics,
s not absolutely necessary. The documentation that comes
with Flash expounds on all of these topics, so if you find yourself
confused or want to learn more, you can check out those examples.
You can also always ask questions on any chapter in this topic at
re an experienced AS3 user, be
ll get through the basics as quickly as possible and
move on to the fun stuff!
Part 1: Classes
As we learned in Chapter 1, classes are essentially the blueprints for
objects in ActionScript (and many other object-oriented program-
ming languages). They define the properties that are inherent to that
object, as well as the methods that determine how that object func-
tions on its own and as part of a larger context. When you create an
object from a class, that object is known as an instance of that class.
Every instance of a class may have different specific values for its
properties, but they all share the common architecture, so Flash
knows that all instances of a certain class will behave in the same
way. In its simplest form, instantiation , or creation, of an object
looks like the one shown below in ActionScript.
var myObject:MyClass = new MyClass();