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

Accessing Definitions from Within a Function

A function's location in a program governs its ability to access the program's definitions (e.g., classes, variables, methods, namespaces, interfaces, and other functions). For a complete description of what can and cannot be accessed from code within functions, see the section "Function Scope" in Chapter 16.

Note, however, that within a function closure, the this keyword always refers to the global object, no matter where the function is defined. To access the current object within a nested function in an instance method, assign this to a variable, as shown in the following code:

public function m () {
  var currentObject = this;

  function f () {
    // Access to currentObject is granted here
    trace(currentObject);  // Displays the object through
                           // which m() was invoked
  }
}

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