Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Flash ActionScript switch Conditional Statement

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

Although the if statement is easy to read and understand. However it becomes difficult to read when the structure is too long. The switch conditional statement is more suitable when there are a lot of conditions need to be compared. The following diagram illustrate the basic structure of a switch statement.

switch conditional statement

Flash ActionScript Codes:

// Declare the variable (myAge)
// Assign int to the data type of myAge
// Store the value of my Age
var myAge:int = 28;

// Test the age by using the Switch conditional statement

case 20:
output_txt.htmlText = "Yes! I am 20 years old!";

case 25:
output_txt.htmlText = "Yes! I am 25 years old!";

case 30:
output_txt.htmlText = "Yes! I am 30 years old!";

case 35:
output_txt.htmlText = "Yes! I am 35 years old!";

output_txt.htmlText = "Ha Ha! I am " + myAge + " years old!";

Download Flash Source File:

Flash Source File switch-condition-statement.fla

Comparison Operators

The following are some commonly used comparison operators:

Meaning Example
== Equal to if (myAge == 30) {
!= Not equal to if (myAge != 25) {
< Smaller than if (myAge <50) {
<= Smaller than or Equal to if (myAge <= 20) {
> Greater than if (myAge > 55) {
>= Greater than or Equal to if (myAge >= 60) {



Many beginner sometimes forget to use the break line and spend a lot of time to find the bug. When the break line is not used, the next line will be executed