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

Source-File-Level Functions

When a function definition occurs at the top-level of a source file, outside any package body, it creates a function that is available within that specific source file only. The following generalized code demonstrates. It shows the contents of a source file, A.as, which contains a package definition, a class definition, and a source-file-level function definition. Because the function is defined outside the package statement, it can be used anywhere within A.as, but is inaccessible to code outside of A.as.

package {
  // Ok to use f() here
  class A {
    // Ok to use f() here
    public function A () {
      // Ok to use f() here
    }
  }
}

// Ok to use f() here

function f () {
}

In the preceding code, notice that f( )'s definition does not, and must not, include any access-control modifier (public, internal, etc.).

Tip

Access-control modifiers cannot be included in source-file-level function definitions.

Source-file-level functions are sometimes used to define supporting tasks for a single class (such as class A in the preceding code). However, because private static methods can also define supporting tasks for a class, source-file-level functions are rarely seen in real-world ActionScript programs.

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