User Guide

58 ActionScript Language and Syntax
trace("Number: " + myNum);
}
}
dynamicTest(100)
dynamicTest("one hundred");
Run-time type checking
Run-time type checking occurs in ActionScript 3.0 whether you compile in strict mode or
standard mode. Consider a situation in which the value 3 is passed as an argument to a
function that expects an array. In strict mode, the compiler will generate an error because the
value 3 is not compatible with the data type Array. If you disable strict mode, and run in
standard mode, the compiler does not complain about the type mismatch, but run-time type
checking by Flash Player results in a run-time error.
The following example shows a function named
typeTest() that expects an Array argument
but is passed a value of 3. This causes a run-time error in standard mode because the value 3 is
not a member of the parameter’s declared data type (Array).
function typeTest(xParam:Array)
{
trace(xParam);
}
var myNum:Number = 3;
typeTest(myNum);
// run-time error in ActionScript 3.0 standard mode
There may also be situations where you get a run-time type error even when you are operating
in strict mode. This is possible if you use strict mode, but opt out of compile-time type
checking by using an untyped variable. When you use an untyped variable, you are not
eliminating type checking, but rather deferring it until run time. For example, if the
myNum
variable in the previous example does not have a declared data type, the compiler cannot
detect the type mismatch, but Flash Player will generate a run-time error because it compares
the run-time value of
myNum, which is set to 3 as a result of the assignment statement, with the
type of
xParam, which is set to the Array data type.
function typeTest(xParam:Array)
{
trace(xParam);
}
var myNum = 3;
typeTest(myNum);
// run-time error in ActionScript 3.0