EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 147

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About statements 147
3. Select Control > Test Movie to test the ActionScript.
In this code, you create a string called
currentHour that holds the current hour number
(for example, if its 6:19 pm,
currentHour holds the number 18). You use the
getHours() method of the Date class to get the current hour. Then you can use the
if..else if statement to trace information to the Output panel, based on the number
that returns. For more information, see the comments in the previous code snippet.
Using a switch statement
The switch statement creates a branching structure for ActionScript statements. Similar to
the
if statement, the switch statement tests a condition and executes statements if the
condition returns a value of
true.
When you use a
switch statement, the break statement instructs Flash to skip the rest of the
statements in that case block and jump to the first statement that follows the enclosing
switch statement. If a case block doesnt contain a break statement, a condition called “fall
through” occurs. In this situation, the following case statement also executes until a break
statement is encountered or the
switch statement ends. This behavior is demonstrated in the
following example, where the first case statement doesnt contain a break statement and
therefore both of the code blocks for the first two cases (A and B) execute.
All
switch statements should include a default case. The default case should always be the
last case on a
switch statement and should also include a break statement to prevent a fall-
through error if another case is added. For example, if the condition in the following example
evaluates to A, both the statements for case A and B execute, because case A lacks a
break
statement. When a case falls through, it does not have a break statement, but includes a
comment in the
break statement’s place, which you can see in the following example after
case A. Use the following format when you write
switch statements:
switch (condition) {
case A :
// statements
// falls through
case B :
// statements
break;
case Z :
// statements
break;
default :
// statements
break;
}

Table of Contents

Related product manuals