Switch Statement - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

switch statement

switch (expression){caseClause: [defaultClause:] }
Creates a branching structure for ActionScript statements. As with the
statement tests a condition and executes statements if the condition returns a value
switch
of
. All switch statements should include a default case. The default case should include a
true
break 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.
Availability: ActionScript 1.0; Flash Lite 1.0
Parameters
- Any expression.
expression
Example
In the following example, if the
evaluates to
, the
A
trace
evaluates to
, the
a
trace()
expression matches the
statement that follows the
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" :
case "i" :
trace("you pressed I or i");
break;
default :
trace("you pressed some other key");
break;
}
};
Key.addListener(listenerObj);
String.fromCharCode(Key.getAscii())
() statement that follows
statement that follows
String.fromCharCode(Key.getAscii())
keyword executes.
default
executes; if the parameter
case "A"
executes; and so on. If no
case "a"
parameter, the
statement, the
if
parameter
case
trace()
Statements
215

Advertisement

Table of Contents
loading

Table of Contents