O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

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

Class Scope

Code placed at the top-level of a class body resides in that class's scope. Here's the code:

package {
  public class SomeClass {
    // Code here is in the someClass scope
  }
}

Tip

Remember that code placed at the top-level of a class body is wrapped in an automatically created static method (the class initializer), which executes when ActionScript defines the class at runtime. See the section "The Class Initializer" in Chapter 4.

Via the scope chain, code in a classs scope can access the following definitions:

  • All definitions available to code in the global scope

Additionally, code in a class's scope can access the following definitions:

  • Static methods and static variables defined by the class

  • Static methods and static variables defined by the class's ancestors, if any (i.e., superclass, superclass's superclass, etc.)

In other words:

package {
  public class SomeClass extends SomeParentClass {
    // Static variables and static methods defined here are
    // accessible througout SomeClass
  }
}

package {
  public class SomeParentClass {
    // Static variables and static methods defined here are
    // accessible througout SomeClass
  }
}

Remember that even though a class can access its ancestors' static variables and methods, static variables and methods are not inherited. See the section "Static Methods and Static Variables Not Inherited" in Chapter 6.

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