
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Undefined
|
107
Many internal ActionScript properties and methods describe the Flash movie envi-
ronment in Boolean terms. For example, if we ask, “Is the spacebar being pressed?”
the interpreter answers with a Boolean:
true (yes) or false (no):
// Key.isDown() is a function that returns either true or false
if (Key.isDown(Key.SPACE)) {
// Spacebar is being pressed, so make our spaceship fire
}
In Chapter 5, we’ll learn how to phrase complex logical expressions using Boolean
operators.
Using Boolean Values to Build a Preloader
Let’s consider an applied Boolean example. Suppose we have a document with 500
frames and lots of content. The beginning of our opening sequence, frame 20, is
labeled
intro. We put the following code on frame 2 of that movie’s main timeline:
if (this._framesloaded >= this._totalframes) {
this.gotoAndPlay("intro");
} else {
this.gotoAndPlay(1);
}
When the movie plays, the playhead passes frame 1 and enters frame 2. The Action-
Script interpreter reaches the conditional statement and evaluates the Boolean
expression within it: this._framesloaded >= this._totalframes. While the movie is still
loading,
this._framesloaded is less than the total number of frames in our movie
(
this._totalframes). If this._framesloaded is not greater than or equal to this.
_totalframes
, then the ...