Another advantage of strict data typing is that Flash automatically shows code hints for built-
in objects when they are strictly typed. For more information, see
"About assigning data types
and strict data typing" on page
81.
Files published using ActionScript 1.0 do not respect strict data typing assignments at compile
time, so assigning the wrong type of value to a variable that you have strictly typed doesn't
generate a compiler error.
var myNum:String = "abc";
myNum = 12;
/* No error in ActionScript 1.0, but type mismatch error in ActionScript 2.0
*/
The reason for this is that when you publish a file for ActionScript 1.0, Flash interprets a
statement such as
as slash syntax rather than as strict typing.
var myNum:String = "abc"
(ActionScript 2.0 doesn't support slash syntax.) This behavior can result in an object that is
assigned to a variable of the wrong type, causing the compiler to let illegal method calls and
undefined property references pass through unreported.
Files published using ActionScript 2.0 can optionally use data typing. Therefore, if you
implement strict data typing in your code, make sure you set your publish settings to
ActionScript 2.0. You can specify the publish settings and define which version of
ActionScript you want to publish your files as by modifying the publish settings from the
main menu (File > Publish Settings) or by clicking the Settings button in the Property
inspector (make sure no instances are selected). To use a specific version of ActionScript or the
Flash Player, select the Flash tab in the Publish Settings dialog box, and make a selection from
the ActionScript version pop-up menu.
For information on type checking, see
"About type checking" on page
84.
About type checking
Type checking refers to verifying that the type of a variable and an expression are compatible.
Therefore, Flash checks that the type you specify for a variable matches the value(s) that you
assign to it. For more information on strict data types and assigning data types, see
"About
assigning data types and strict data typing" on page 81
and
"Assigning a data type"
on page
82.
Type checking can occur at either compile time or runtime. If you use strict data typing, type
checking occurs at compile time. Because ActionScript is a dynamically typed language,
ActionScript can also type checking at runtime.
84
Data and Data Types
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?