O'Reilly logo

ActionScript 3.0 Bible by Roger Braunstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Object Oriented Programming

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 that 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.

Understanding Classes

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, and occasionally a bike pump. If you model the bicycle as a class, you can represent all of these and carefully design it to interact with the other objects in the right ways. Let's call this class Bicycle. I will come back to the Bicycle class to describe concepts in class design throughout this chapter.

You can use classes throughout your program to model tangible ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required