User Guide

Assigning data types to elements 39
Null data type
The null data type has only one value,
null. This value means no value—that is, a lack of data.
You can assign the
null value in a variety of situations to indicate that a property or variable does
not yet have a value assigned to it. The following list shows some examples:
To indicate that a variable exists but has not yet received a value
To indicate that a variable exists but no longer contains a value
As the return value of a function, to indicate that no value was available to be returned by
the function
As a parameter to a function, to indicate that a parameter is being omitted
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