Skip to main content
March 14, 2012
Question

Visible / invisible movieclip...

  • March 14, 2012
  • 1 reply
  • 924 views

Hello!

I have a movieclip, and I want to make it visible / invisible. I have written a code, but it is not working. When I click on the button, nothing happens.

import flash.events.MouseEvent;

import flash.display.DisplayObject;

stop();

jatek_btn.addEventListener (MouseEvent.CLICK, gojatek);

uk_btn.addEventListener (MouseEvent.CLICK, gokerdesek);

function gojatek(evt:MouseEvent):void {

gotoAndStop(2);

}

function gokerdesek(evt:MouseEvent):void{

if (kerdesek_mc.DisplayObject.visible == false)

{

kerdesek_mc.DisplayObject.visible == true;      

}

else if (kerdesek_mc.DisplayObject.visible == true)

{

kerdesek_mc.DisplayObject.visible == false;

}

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 14, 2012

When you assign a value you use "="

When you are comparing value for equality you use "=="

With that said, it appears you just want to toggle it back and forth, so your function can simply be...

function gokerdesek(evt:MouseEvent):void{

    kerdesek_mc.DisplayObject.visible = !kerdesek_mc.DisplayObject.visible;      

}

The "!" exclamation basically says "not",  so that one line says make the visible property whatever it is not

March 14, 2012

Thanks for your response. I have just started learning Flash / AS, and I find actionscript pretty neat. I have some C/C# experience, and I can see a lot of similarities between AS and C/C#.

Ned Murphy
Legend
March 14, 2012

You're welcome.  Many programming languages are similar which makes it easier for programmers to adapt, though sometimes the minor differences can make things a little confusing when you start juggling a few simultaneously.