In Macromedia Flash, using if/else statements (and the substitutes) are quite similar to other programming languages. Using an if statement is easy:
if (statement) {
//actions
}
If the actions between the brackets is true [variable equals 100], then do the following actions.
You can also use if/else statements; in two ways:
as an else if statement:
if (statement) {
//actions
} else if (statement) {
//actions
}
If the actions between the brackets is true [variable equals 100], then do the following actions, or if the actions between the second brackets is true [variable equals 200], then do the following actions.
..Or as an if/else statement:
if (statement) {
//actions
} else {
//actions
}
If the actions between the brackets is true [variable equals 100], then do the following actions, otherwise do the following actions.
Pretty simple, eh?
Switch/case statements are pretty much like if statements, except the syntax is a little different:
switch (statement) {
case value1 :
//actions
break;
}
Switch is the variable that you will be defining and value1 is what you want your variable equal to do the following actions.
You can also use multiple case statements in a swtich statement, and just like the if/else, you have the default statement:
switch (statement) {
case value1 :
//actions
break;
case value3 :
//actions
break;
default :
//actions
break;
}
If the variable equals value1, do actions but if the variable equals value2 do actions but if the variable equals value3 do actions otherwise do actions. Get it?
One more thing about switch/case statements, YOU MUST put the break statement at the end, or else the code will run through each case statement and do all of the actions, creating a big BIG mess of things.
And finally, we have ?/: statements.
They work the same, except the ? is used as an if statement and the : is used as the else statement:
statemnt ? //actions : //actions
You can also put multiple statements together, like so:
statement1 ? //actions : statement2 ? //actions : //actions
Two more things on ?/: statements, if you don't want any actions after the : then put
null; after it, and if you want to declare multiple actions after the ? or the : you must put the in brackets and seperate them with a comma, like so:
statement ? (//actions, //actions) : (//actions, //actions)
Here's a few examples incase you didn't quite get all of that:
if/else statement:
if (variable == 100) {
trace("variable equals 100");
} else if (variable == 200) {
trace("variable equals 200");
} else {
trace("variable doesn't equal 100 or 200");
}
switch/case statement:
switch (variable) {
case 100 :
trace("variable equals 100");
break;
case 200 :
trace("variable equals 200");
break;
default :
trace("variable doesn't equal 100 or 200");
break;
}
?/: statement:
variable == 100 ? trace("variable equals 100") : variable == 200 ? (trace("variable doesn't equal 100:"), trace("it equals 200")) : null;
Well, that's about it. Hope this helped! :D