MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 136

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

For more information on objects and properties, see
of constants in the language (such as
> Constants category in the ActionScript 2.0 Language Reference.
Using constants
Constants are properties with a fixed value that cannot be altered; in other words, they are
values that don't change throughout an application. The ActionScript language contains many
predefined constants. For example, the constants
properties of the Key class and refer to keyboard keys. The constant
same meaning: it indicates the Tab key on a keyboard. Constants are useful for comparing
values and for using values in your application that do not change.
To test whether the user is pressing the Enter key, you could use the following statement:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
trace("Are you ready to play?");
}
};
Key.addListener(keyListener);
For the previous ActionScript to work, it may be necessary to disable keyboard shortcuts in
the authoring environment. Select Control > Test Movie from the main menu, then while
previewing the SWF file in the player, select Control > Disable Keyboard Shortcuts from the
SWF file's preview window.
In Flash there is no way to create your own constant values except when you create your own
custom classes with private member variables. You cannot create a "read-only" variable
within Flash.
Variables should be lowercase or mixed-case letters; however, constants (variables that do not
change) should be uppercase. Separate words with underscores, as the following ActionScript
shows:
var BASE_URL:String = "http://www.macromedia.com"; //constant
var MAX_WIDTH:Number = 10;
Write static constants in uppercase, and separate words with an underscore. Do not directly
code numerical constants unless the constant is 1, 0, or -1, which you might use in a
as a counter value.
You can use constants for situations in which you need to refer to a property whose value
never changes. This helps you find typographical mistakes in your code that you might not
find if you use literals. It also lets you change the value in a single place. For more information
on literals, see
"About literals" on page
136
Syntax and Language Fundamentals
"Object data type" on page
and
), see the ActionScript Language Elements
false
NaN
BACKSPACE
130.
78. For a list
,
,
, and
ENTER
SPACE
always has the
Key.TAB
//constant
are
TAB
loop
for

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents