0

Hi, I have two objects: One is a button (instance name button1) and a square (instance name square1), and I would like the square's visibility to be toggled on or off when the button is clicked. So far, my code can make the square disappear, but not reappear. Below is my current code:

square1.visible = true;
button1.addEventListener(MouseEvent.MOUSE_UP, squareVisible);
function squareVisible (e:MouseEvent):void {
	if (square1.visible = true){
		square1.visible = false;
	} else if (square1.visible = false){
		square1.visible = true;
	}
}

Thanks for your help! :)

Edited by csterling: Edited for clarity

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by misd_bunder
0

Try these code with some modifications in the condition

square1.visible = true;
button1.addEventListener(MouseEvent.MOUSE_UP, squareVisible);
function squareVisible (e:MouseEvent):void{
    if (square1.visible == true)
{       square1.visible = false;    } 
else if (square1.visible == false)
{       square1.visible = true; }
}

end-quote

Hi, I have two objects: One is a button (instance name button1) and a square (instance name square1), and I would like the square's visibility to be toggled on or off when the button is clicked. So far, my code can make the square disappear, but not reappear. Below is my current code:

square1.visible = true;
button1.addEventListener(MouseEvent.MOUSE_UP, squareVisible);
function squareVisible (e:MouseEvent):void {
    if (square1.visible = true){
        square1.visible = false;
    } else if (square1.visible = false){
        square1.visible = true;
    }
}

Thanks for your help! :)

Edited by mike_2000_17: Fixed formatting

0

Thanks for the help, but it still hasn't fixed my problem...The square disappears but when it is not visible it does not reappear when the button is clicked...

0

I had tested that code. It still works.
If you are not having the result , then make change in the function declaration as

function squareVisible (event:MouseEvent)

instead of

function squareVisible (e:MouseEvent)

and use a separate layer for actionscript3.0

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.