O'Reilly logo

Actionscript Cookbook by Joey Lott

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 12. Objects and Custom Components

Introduction

ActionScript is an object-based language. The entire language is composed primarily of blueprints, called classes, for different types of objects. Based on these blueprints you, as the developer, can construct many instances of many types of objects, and each instance automatically inherits all the characteristics and functionality of its class. For example, all arrays are members of the Array class, which defines the length property as well as the methods (concat( ), sort( ), etc.) that all arrays inherit.

Therefore, whenever you are using ActionScript, you are inherently using objects and object-oriented programming. Understanding the inner workings of ActionScript classes and objects puts you well on your way to harnessing the true power of the language. This knowledge enables you to add properties and methods to individual instances (objects) and to the classes they inherit from.

Every class in ActionScript has a prototype property. The prototype property contains an object from which all instances of the class inherit properties and methods.

Tip

If you add a property or method to a class’s prototype, all instances of that class automatically inherit that custom property or method.

Here is an example:

// Add a property to the Array class.
Array.prototype.testProperty = "this is a test property";

// Create a new array. This array inherits, along with all of the other properties
// and methods of the Array class, the custom testProperty ...

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