
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
106
|
Chapter 4: Primitive Datatypes
The eval() function was used frequently in Flash 4 to generate variables dynamically
because support for arrays wasn’t available until Flash 5. Such uses of eval() should
be rewritten using arrays when upgrading legacy code.
The Boolean Type
Boolean data is used to represent the logical states of truth and falsehood. Hence
there are only two legal values of the boolean datatype:
true and false. Notice that
there are no quotation marks around the words
true and false because Boolean data
is not string data. The keywords true and false are reserved primitive data values
and cannot be used as variable names or identifiers.
We use Boolean values with conditional expressions to add logic to the execution of
code. For example, we might assign the value
true to a variable that tracks the status
of a spaceship’s firepower:
shipHasDoubleShots = true;
By comparing shipHasDoubleShots to the Boolean literal true, we can decide how
much damage to inflict when a shot hits its target:
if (shipHasDoubleShots = = true) {
// Shoot them with twice the power.
// This will be reached if the comparison is true.
} else {
// Shoot them with a single dose.
// This will be reached if the comparison is false.
}
When the double-shot power runs out, we can set the variable to false