Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If/Else Statement on a Button 2

Status
Not open for further replies.

CarddassX

Programmer
Apr 2, 2002
9
US
I have a movie instance in my frame which I named 'helpmenu'. I tried to make code that would allow a user to control the visibility of the menu. I'm able to get the menu to disappear by pressing 'h', but I can't seem to figure out how to make it reappear. I placed the coding for this action on the X box in the top right corner since the keypress function only works on a button:
-------------------------------------------------
on (keyPress "h") {
if ("0") {
setProperty (helpmenu, _alpha, "100");
} else {
setProperty (helpmenu, _alpha, "0");
}
}
-------------------------------------------------

Here is the current version of the file with the above code at work:


I can't tell if it's a syntax problem or just the wrong coding altogether. I tried following a tutorial that explained if/else statements, but I couldn't seem to get it to work for my particular case. Maybe it needs a Variables? Thanks in advance!

-Cardy
 
This sets up a global variable, menu_up (default is false) and the if statement then acts according to it's value.

on (keyPress "h") {
if (_root.menu_up == true) {
setProperty (helpmenu, _alpha, "0");
_root.meu_up = false;
} else {
setProperty (helpmenu, _alpha, "100");
_root.menu_up = true;
}
}

You end up with a toggle: when the menu is up (true) it's alpha is set to 0, and when it's not visible (else), it's alpha is set to 100.
You could achieve the same results with the _visible property, just setting it to true or false.

Regards,
new.gif
 
Thanks oldnewbie, that coding worked perfect.

Cheers,
-Cardy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top