MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 211

Actionscript language reference
Table of Contents

Advertisement

switch
Availability
Flash Player 4.
Usage
switch (expression){
caseClause:
[defaultClause:]
}
Parameters
Any expression.
expression
A
caseClause
execute if the expression matches the switch
defaultClause
expressions match the switch
Returns
Nothing.
Description
Statement; creates a branching structure for ActionScript statements. As with the
the
statement tests a condition and executes statements if the condition returns a value of
switch
. All switch statements should include a default case. The default case should include a break
true
statement that prevents a fall-through error if another case is added later. When a case falls
through, it doesn't have a break statement.
Example
In the following example, if the
to
, the
A
trace()
statement that follows
trace()
String.fromCharCode(Key.getAscii())
keyword executes.
default
var listenerObj:Object = new Object();
listenerObj.onKeyDown = function() {
switch (String.fromCharCode(Key.getAscii())) {
case "A" :
trace("you pressed A");
break;
case "a" :
trace("you pressed a");
break;
case "E" :
case "e" :
trace("you pressed E or e");
break;
case "I" :
ActionScript Core Language Elements
keyword followed by an expression, a colon, and a group of statements to
case
A
keyword followed by statements to execute if none of the case
default
expression
String.fromCharCode(Key.getAscii())
statement that follows
case "a"
parameter using strict equality (
expression
parameter strict equality (
executes; if the parameter evaluates to
case "A"
executes; and so on. If no
parameter, the
trace()
CHAPTER 5
===
).
===
statement,
if
parameter evaluates
a
expression matches the
case
statement that follows the
switch
).
, the
211

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents