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 hasn’t been assigned, either by your code or user interaction.
The value
undefined
is automatically assigned; unlike
null
, you don’t 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
Содержание FLEX
Страница 1: ...Flex ActionScript Language Reference ...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Страница 135: ...case 135 See also break default strict equality switch ...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in ...
Страница 808: ...808 Chapter 7 ActionScript for Flash ...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators ...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Страница 822: ...822 Index ...