
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
162
|
Chapter 7: Conditionals
default:
trace("x is not 1, 3, or 5");
}
The switch statement implicitly uses the strict equality operator (===), not the equal-
ity operator (
==), when comparing the testExpression with case expressions. For a
description of the difference, see Chapter 5. The expressions following the
switch
and case keywords can be any datatype and need not be literal values. Because a
switch statement executes from top to bottom, case expressions that are most likely
to match
testExpression should be listed first (obviously, this applies only to situa-
tions where case statement order does not affect the result of the switch statement).
Although the switch statement was introduced for Flash Player 6, code using switch
can be exported from the Flash MX authoring tool to Flash Player 5 and Flash Player
4 formatted movies. When exporting to Flash 4 or Flash 5 format, however, switch
expression matching uses the standard equality (
==), not the strict equality (===)
operator. In any case, switch does not offer any performance improvement over the
analogous if-else if-else construction.
Note that
case and default clauses are two specific examples of a more general struc-
ture called a statement label. Statement labels are a part of ECMAScript v3, but—
other than
case and default