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
var pet:VirtualPet = new VirtualPet("Stan");
Next, the following code attempts to access a nonexistent
method, eatt( ), through the
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 ...