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

Detecting Reference Errors at Compile Time

At the beginning of this chapter, we learned that an attempt to access a nonexistent variable or method results in a reference error. When a program is compiled in standard mode, reference errors are not reported by the compiler. Instead, when the program runs in the debugger version of a Flash runtime, reference errors manifest as runtime exceptions. By contrast, when a program is compiled in strict mode, references to nonexistent variables or methods made through typed expressions are reported by the compiler, and cause compilation to fail.

For example, the following code creates a variable, pet, of type VirtualPet, and assigns that variable an instance of the VirtualPet class:

var pet:VirtualPet = new VirtualPet("Stan");

Next, the following code attempts to access a nonexistent method, eatt( ), through the typed variable pet:

pet.eatt(new Sushi());

In standard mode, the preceding code compiles, but generates a runtime reference error. In strict mode, the preceding code generates the following compile-time reference error and fails to compile.

1061: Call to a possibly undefined method eatt through a
  reference with static type zoo:VirtualPet.

Service with a smile.

Note, however, that the compiler does not report reference errors made through untyped expressions. Furthermore, references to nonexistent variables and methods made through instances of dynamic classes (such as Object) do not generate reference errors of any kind; instead, such references ...

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