Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 58

Programming actionscript 3.0
Table of Contents

Advertisement

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
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
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
type of
, which is set to the Array data type.
xParam
function typeTest(xParam:Array)
{
trace(xParam);
}
var myNum = 3;
typeTest(myNum);
// run-time error in ActionScript 3.0
58
ActionScript Language and Syntax
, which is set to 3 as a result of the assignment statement, with the
myNum
that expects an Array argument
typeTest()
myNum

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents