Chapter 10. Objects and Dictionaries
FEATURED CLASSES
Object
Dictionary
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, "Arrays," I showed how to use arrays to store associative data. In this chapter you will see how to use the Object
and Dictionary
data types to store and retrieve this kind of information and explore other situations where Objects
are useful.
Working with Objects
The class Object
is found at the root of the type hierarchy of all classes. Simple classes like Number
and String
extend Object
directly; classes like Sprite
descend from Object
. In other words, every object in the ActionScript 3.0 world is an Object
. The Object
class by itself doesn't do much and would hardly merit its own chapter 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. Programming with dynamic classes is usually a poor choice. If you were programming a dinner set as a dynamic class, some code you don't control could overwrite your saltShaker
property to dispense habanero peppers, ruining a perfectly good meal. A chaotic world like that is no world to live in, so every class I write in this book ...
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.