AS3 switch/case statement syntax

   Posted May 15, 2007 by David Kirk in Computer programming

This howto describes the basic usage of switch/case statements in actionscript.


Case/Switch statements are frequently used for complex if/then coding. Here is a basic example of how to build these constructs.


switch (example_string)
{
case "a":
trace ("a was selected");
break;
case "b":
trace ("b was selected");
break;
default:
trace ("Neither a or b was selected")
}

By leaving out the break, you can create the same action for several different case statements…


switch (example_string)
{
case "a":
case "b":
trace ("either a or b was selected");
break;
default:
trace ("Neither a or b was selected")
}

 

About David Kirk

David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
View more articles by David Kirk

The Conversation

Follow the reactions below and share your own thoughts.