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 theArrayclass. 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 theArrayclass, the customtestProperty ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access