Default
Top  Previous  Next


The Default action defines a statement or set of statements if an argument can find no matches within a Switch conditional. It would be the same as using an Else action with an IF condtitional.


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;
        default:
        trace("Cannot find a match for the variable 'i'");
    }
}
onFrame (1) {
    i = 4;
    testSwitch();
}
// Since the variable "i" is not equal to any of the defined Cases within the Switch action, "Cannot find a match for the variable 'i'" will be displayed in the debug window.

This could 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");
} else {
    trace("Cannot find a match for the variable 'i'");
}