Case
Top  Previous  Next


The Case action is a condition used within a Switch action. A statement or set of statements will be executed if this case is the same as the argument provided within the Switch action. A Case can be compared to the IF conditional action. A single Case would be the same as using a single IF conditional, and multiple Cases would be the same as adding multiple Else IF conditional actions.

Actions_case

Example:

Function
 testSwitch() {
    switch (i) {
        Case
 1:
        trace("i is equal to 1");
        break;
        Case
 2:
        trace("i is equal to 2");
        break;
        Case
 3:
        trace("i is equal to 3");
        break;
    }
}
onFrame (1) {
    i = 2;
    testSwitch();
}

// displays "i is equal to 2" In the Debug window.

This could be compared to:

if (i == 1) {
    trace("i is equal to 1");
} else if (i == 2) {
    trace("i is equal to 2");
} else if (i == 3) {
    trace("i is equal to 3");
}