Simple If/Else with Button

Hello. This is probably an easy question. I have a button that turns a movieclip on and off. I want to be able to use the same button to turn this on/off. I figured you could use the if/else statements but can’t seem to figure it out. Basically, when the mc is on, the button should turn it off, and vice versa. I have been using an ugly work around for this and I’m just looking for a cleaner, more proper way.

Thanks.

do you mean make it visible/invisible? You probably want to create a variable that sets the state of the movieclip at the beginning (e.g. variable = on), then you can say if variable = on set visibility to false and variable = off, else if variable = off set visibility to true and variable = on.

:hr:

What lunatic said, but if you want it as simple as possible, exclude the variable and use [AS]myMc.visible = !myMc.visible;[/AS] :cowboy:

Thanks for the quick reply. Toggling the visibility would be fine. Something is wrong with the code I’m using. I have the following:

myMc = "on";
if (myMc == "on") {
	myMc._visible = true;
} else if (myMc == "off") {
	myMc._visible = false;
}

myButton.onPress = function() {
	if (myMc == "on") {
		myMc = "off";
	} else {
		myMc = "on";
	}
};

What am I doing wrong?

[AS]myButton.onPress = function() {
_parent.myMc._visible = !_parent.myMc._visible;
};[/AS]change _parent to the appropriate scope.

That worked. Thanks for the help, this will save me lots of time.

No problem! :cowboy:

nice bluenar, i’ve never seen that before :slight_smile:

Aye, you can negate any boolean variable/property. :slight_smile: Really useful.