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 theArray
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 theArray
class, the customtestProperty ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.