Chapter 10. Objects and Dictionaries
FEATURED CLASSES
ObjectDictionary
All classes extend Object—it is the root of the ActionScript class hierarchy. Despite their inauspicious roots, Objects 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 ...
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