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

Instance Method Scope

Code placed in an instance method body resides in that method's scope. Here's the code:

package {
  public class SomeClass {
    public function instanceMeth () {
      // Code here is in the instanceMeth scope
    }
  }
}

Via the scope chain, code in an instance method's scope can access these definitions:

  • All definitions available to code in the global scope

  • All definitions available to code in the scope of the class containing the instance method definition

Additionally, code in an instance method's scope can access these definitions:

  • All instance methods and instance variables of the object through which the instance method was invoked (subject to the limitations imposed by access-control modifiers)

  • All local variables, nested functions, and namespaces defined within the instance method

The following code demonstrates:

package {
  public class SomeClass extends SomeParentClass {
    public function instanceMeth () {
      // 1) All instance methods and instance variables of the current
      //    object (i.e., this) are accessible throughout instanceMeth()
      //   (subject to the limitations imposed by access-control modifiers)

      // 2) Local variables, nested functions, and namespaces defined here
      //    are accessible throughout instanceMeth()
    }
  }
}

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