Chapter 17. Namespaces
In very general terms, a namespace is a set of names that contains no duplicates. That is, within the set, each name is unique. For example, in English, the names of fruits could be considered a namespace because each fruit has its own unique name—apple, pear, orange, and so on. Likewise, the names of colors could be considered a namespace because each color has its own unique name—blue, green, orange, and so on.
Notice that the name “orange” appears in both groups of names. The name “orange” itself is not unique, it is unique only within each group. Depending on whether you’re talking about a fruit or a color, the same name, “orange,” refers to two different things. That’s the purpose of namespaces. They let the same name (identifier) have different meanings depending on the context in which it is used.
When applied to programming, this “same name, different meaning” feature of namespaces offers two general benefits:
It helps programmers avoid name conflicts
It lets a program’s behavior adapt to the current context
Over the course of this chapter, we’ll explore the many nooks and crannies of namespaces in ActionScript. Try not to let the various details distract you from the relative simplicity of namespaces. Fundamentally, namespaces are nothing more than a two-part naming system. They are used to distinguish one group of names from another, much like an area code distinguishes one phone number from other phone numbers around the world.
Namespace Vocabulary
In ...
Get Essential ActionScript 3.0 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.