PDA

View Full Version : If Commands!


Mr.Moo
02-16-2004, 06:45 PM
Hi!

I know what if commands do but i just do not know how to use them. For example:

There are 2 buttons, button A and button B. When you press button A, it turns red, and when you press button B, it has to recognize if button A if red or not. If button A is red then an animation should play.

Hope thtas not to hard to understand. Can anyone tell me how to use the if command to recognize if button A is red or point me to a tutorial?

Thanks!

Cota
02-16-2004, 07:00 PM
The if statement itself is simple enough:

if (condition goes here){
//Do something
}else{
//Do something else
}

Or the else if:

if (condition goes here){
//Do something
}else if (condition){
//Do something else
}else if (condition){
//do something
}

For you specific problem, I would set a variable to hold the button color.

If (button_color == "red"){
gotoAndPlay(1);
} else if (button_color == "green"){
gotoAndPlay(2);
}

Does that help?

Mr.Moo
02-16-2004, 08:54 PM
Yeah that help alot! But i still dont understand one thing...

If (button_color == "red"){
gotoAndPlay(1);
} else if (button_color == "green"){
gotoAndPlay(2);
}

How did you come up with "button_color == "red""? What is "button_color"? is it the instance name of the button? and hwo does the AS know the statement "red" and its relationaship with the movie clip?:confused:

Cota
02-16-2004, 09:12 PM
button_color would be a variable name, sorry, just off the top of my head. "red" would the value of that variable. You said when button A is pressed, it should turn red, and button B should know what color button A is.

Button A code:

on(release){
_global.button_color = "red"
//code to change button color
}

code for button B:

on(release){
If (_global.button_color == "red"){
gotoAndPlay(1);
} else if (_global.button_color != "red"){
gotoAndPlay(2);
}

Mr.Moo
02-16-2004, 10:09 PM
OoOoOo! Thanks Man! Now i get it!:D :D :D

Edit: WOW!!! OMG! It worked!! I was triing so hard before and now it worked so easily!!!! OMG THANKS MAN!! LOL im going crazy.. i really needed this!

Cota
02-16-2004, 10:32 PM
Not a problem

subquark
02-19-2004, 12:53 PM
very nice explanation Cota! thanks :)