Chapter 9. Using Objects
Introduction
In this chapter
Using Objects and Dictionaries to manipulate associative arrays
Using Object as the root class
Applying Objects to common tasks
All classes extend Object
—it is the root of the ActionScript class hierarchy. Despite their inauspicious roots, Object
s can be truly useful as a data structure. In Chapter 8, we show how arrays might be used to store associative data. In this chapter you see how to use Object
s and other classes to store and retrieve this kind of information, and explore other situations where Object
s are useful.
Working with Objects
The class Object
is found at the root of all type hierarchies of all classes. In other words, every object in the ActionScript 3.0 world is an Object
. The Object
class by itself doesn't do much and, in fact, would easily be the simplest thing you could create, but for the interesting property that the Object
class is one of the few classes that is dynamic.
Dynamic classes
Dynamic classes can be extended at runtime with new properties and methods. This means you can take the data and operations that define an object and rename them, rewire them, or add to them while the program is running. If Forrest Gump were a programmer, he might tell you that dynamic objects are like a box of chocolates: You never know what you're gonna get. This makes programming with dynamic classes usually a poor choice. If you were programming a dinner set as a dynamic class, some code you don't control could overwrite your ...
Get ActionScript™ 3.0 Bible 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.