Chapter 3. Programming with Classes
In this chapter
Understanding classes, objects, and types
Introducing methods and properties
Programming using classes is essential to take advantage of the full power of ActionScript 3.0. By using classes, you participate in object‐oriented programming, a versatile way to think about and structure code. Objects are high‐level building blocks, and classes are the constructs which define them. In this chapter you learn what constitutes a class, how classes relate to objects and other language constructs, and how to write a class in ActionScript 3.0.
To program using classes, you must understand what classes are. Classes perform multiple roles in object‐oriented programming, and there are many ways to think about them. This section introduces these fundamental ideas.
Classes can model the real world
Classes often work best, and are easiest to think about, when they represent objects in the real world. You can, for example, create a class to represent a bicycle. That bicycle can have a color, a size, and two tires. You can pedal it, brake it, switch gears, and ring the bell. The bicycle has relationships with other real‐world objects: your feet, the road surface, occasionally a bike pump. If we model the bicycle as a class, we can represent all of these, and carefully design ...