User Guide

Assigning data types to elements 23
Several methods and functions return null if no value has been set. The following example
demonstrates how you can use
null to test if form fields currently have form focus:
if (Selection.getFocus() == null) {
trace("no selection");
}
Undefined data type
The undefined data type has one value,
undefined, and is automatically assigned to a variable to
which a value hasnt been assigned, either by your code or user interaction.
The value
undefined is automatically assigned; unlike null, you dont assign undefined to a
variable or property. You use the undefined data type to check if a variable is set or defined. This
data type lets you write code that executes only when the application is running, as shown in the
following example:
if (init == undefined) {
trace("initializing app");
init = true;
}
If your application has multiple frames, the code does not execute a second time because the init
variable is no longer undefined.
Void data type
The void data type has one value,
void, and is used in a function definition to indicate that the
function does not return a value, as shown in the following example:
//Creates a function with a return type Void
function displayFromURL(url:String):Void
Assigning data types to elements
At runtime, Flash Player automatically assigns data types to the following kinds of language
elements, as discussed in the next section:
Variables
Parameters passed to a function, method, or class
Values returned from a function or method
Objects created as subclasses of existing classes
In ActionScript 2.0, you should explicitly assign data types to items, which can help prevent or
diagnose certain errors in your scripts at compile time and offers other benefits. This technique is
called strict data typing.
For more information on assigning data types, see the following topics:
Automatic data typing” on page 24
“Strict data typing” on page 24