Flash as switch statement usage detailed

Source: Internet
Author: User

When a case fails, it does not have a break statement, but there is a comment at the location of the break statement, which you see in the following case a note. When you write a switch statement, use the following format:

The code is as follows Copy Code

Switch (condition) {
Case A:
Statement
Failed
Case B:
Statement
Break
Case Z:
Statement
Break
Default:
Statement
Break
}


Usage of default in switch statements:

Cases:

The code is as follows Copy Code

function Not_set_yet () {
Switch (_root.txt.text) {
Case "Class One":
numb = Random (26) +97;
Case "Class two":
numb = Random (26) +65;
Default:
var tt = random (2);
if (TT = 1) {
numb = Random (26) +97;
} else {
numb = Random (26) +65;
}
}
}

The meaning of this code is that when a class and class two are not established, then, the value of numb to take random (26) +97 and Random (26) +65;

Application examples

The code is as follows Copy Code

var my_arr:array=new Array ();

var _string:string=my_arr[math.floor (Math.random () *my_arr.length)];

Case "Pear":

Break

Trace ("Go for a walk!") Very handsome! ");

Case "Belle One":

Break

Trace ("Go slow, don't fall!");

Case "Computer One":

Break

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.