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! :)

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! :)

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...

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.