• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Objects and Classes > Simulating Namespaces

12.11. Simulating Namespaces

A namespace is a unique area of a program within which all identifiers are guaranteed to be unique. It lets a program use, say, both Company X's and Company Y's unique Ball classes without conflicts (i.e., without one class declaration overwriting the other). ActionScript in Flash MX does not have formal support for namespaces, but we can simulate them by creating a unique global object and defining all of a program's identifiers on it (as we saw in the earlier Section 12.9.2). Typically, the unique global object is named after a domain name, because domains are guaranteed to be unique. For example, to create a namespace for my classes I use the following code (my site's domain is moock.org):

if (_global.org =  = undefined) {
  _global.org = new Object( );
}
if (_global.org.moock =  = undefined) {
  _global.org.moock = new Object( );
}


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint