View Full Version : IF, THEN, =, statements
KingKong
12-08-2004, 08:07 PM
How do you use simple statements like IF, THEN, =, in flash? Also how do you use variables.
for example how would I do this in flash: IF A = 5 THEN...
Hi,
Flash uses an "if/else" method instead of if/then. The format looks like this...
if(some condition == true){
do something;
}
adding an else statement .....
if(some condition == true){
do something;
}else if(some other condition== true){
do something else;
}
So, Your demo would look like...
if(A==5){
execute code here;
}else{
execute some other code;
}
Now, without going too deeply into methods without confusion, I will simply mention that there is also a shorthand for if/else statements, known as "nested conditionals". Basically shorthand for the code samples posted above...
condition ? statement : alternative statement;
A==5 ? trace("A is 5") : trace("A is not 5");
Hope it helps
Regards
NTD
KingKong
12-26-2004, 07:57 PM
Can you have an if statement within an if statement?
e.g. if (condition) {if (another condition) {do something} }
the point is to have two conditions. Is there and AND statement?
e.g. IF A=1 AND B=5 or if (a = 1) and (b = 2) {do something}
Hi,
Yes, you can nest if statements within other if statements. One problem I notice is how your using the = sign. A single equals sign(=) assigns a value. A double equal sign(==) compares a value.
if(a==1 && b==5){
do something;
}
The above requires both conditions to be true before firing the code.
if(a==1){
if(b==2){
do something;
}
}
The above is a nested if statement. The first condition must be true or the second if statement wont fire.
Powered by vBulletin™ Version 4.1.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.