O'Reilly logo

ActionScript 3.0 Bible by Roger Braunstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Objects and Dictionaries

FEATURED CLASSES

  1. Object

  2. Dictionary

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required