Page 1 of 1

Toggle Visibility

PostPosted: Fri Sep 02, 2011 4:24 am
by kojiro
does anyone know how to make a symbol become invisible when clocked then visible when clicked again in action script 3? i tried using these codes

glasses.addEventListener(MouseEvent.CLICK, button_9_clk);

function button_9_clk(event:MouseEvent):void{
glasses.visible = !(glasses.visible)
}


and this

glasses.addEventListener(MouseEvent.MOUSE_UP,But_glasses_Pressed);

function But_glasses_Pressed(event:MouseEvent)
{
Glasses.visible = !( Glasses.visible);
}


but all that happens is the symbol is invisible when clicked but i cant clock again to make it reappear. also zone kind of does something like this but i believe the method is different. there are a few of his flashes where you can toggle character clothing mainly shoes but it seems like for shoes on and off the leg symbol changes but is in sync with the animation when changing back and forth between on and off. any on knows how this is done also?

Re: Toggle Visibility

PostPosted: Fri Sep 02, 2011 7:23 am
by BlueLight
So i program in java so the sytax is a little different but if this was java i would Basically say on mouse click Button_9_clk.setVisible(false)

So just try this
Code: Select All Code
glasses.addEventListener(MouseEvent.CLICK, button_9_clk);

function button_9_clk(event:MouseEvent):void{
button_9_clk.visible = (false)


If that doesn't look like it will work sorry but i can't be much help. Again i know basic java not AS3 but the syntax is similar

Re: Toggle Visibility

PostPosted: Fri Sep 02, 2011 12:03 pm
by GolanTrevize
If it isnt visible you wont be able to click it. Try changing the alpha to 0 (or a very low value if you want to find the button).

Re: Toggle Visibility

PostPosted: Fri Sep 02, 2011 1:14 pm
by BlueLight
GolanTrevize Wrote:If it isnt visible you wont be able to click it. Try changing the alpha to 0 (or a very low value if you want to find the button).

It's seems i didn't understand the question.

Golan is correct. From the sounds of it you want to make the button invisible to the eye but still be able to click it. If this is the case you lower and raise the alpha and this will give you the result you want.

If you want it so the button can't be seen or clicked you set visible to false.

Also i found it neat how you are able to use the "Not" operator to tell it turn visible if not visible and other way.
This will help me in my programming since i've run in to something similar and i use a if statement.
I'm to tired to come up with a way to use it but i'm sure i will find a way.

Re: Toggle Visibility

PostPosted: Fri Sep 02, 2011 6:33 pm
by kojiro
so what kind of actionscript would i use to set the alpha to 0 when clicked then 100 when clicked again? i suck at coding, ive only been using what i found around the net and on this forum

Re: Toggle Visibility

PostPosted: Fri Sep 02, 2011 8:11 pm
by GolanTrevize
At as2 it would be like :

glasses._alpha = 0

I hope it works at AS3

Re: Toggle Visibility

PostPosted: Sat Sep 03, 2011 3:18 am
by kojiro
didnt work just turns invisible and is still a button but wont comeback no matter how many times i click it

Re: Toggle Visibility

PostPosted: Sat Sep 03, 2011 4:34 am
by BlueLight
If statement.

It might look something like this

Code: Select All Code
if( glasses._alpha == 0){
glasses._alpha = 100 //or what ever ever number you want}

else{ glasses._alpha = 0}
but you will have to convert the syntax to fit action script.

Re: Toggle Visibility

PostPosted: Sun Sep 04, 2011 8:15 pm
by miicas
Q.Q if then statements are what made me give up on learning java

Re: Toggle Visibility

PostPosted: Sun Sep 04, 2011 9:18 pm
by GolanTrevize
just change the lines


if( glasses._alpha == 0){
glasses._alpha = 100
}else{
glasses._alpha = 0
}

Re: Toggle Visibility

PostPosted: Sun Sep 04, 2011 9:50 pm
by kojiro
got it to work thanks to scorp29 from FA.

About the glasse, why don't put an invisible button on the glasses, switching the visibility of these one, uusing the ".visible" attribute ?

Would give something like that :



GlassesButton.addEventListener(MouseEvent.MOUSE_UP,But_Glasses_Pressed);

function But_Glasses_Pressed(event:MouseEvent)
{
Glasses.visible = !( Glasses.visible);
}


and this is the fla he sent me showing how it needs to be put together(this is action script 3)

http://www.megaupload.com/?d=9BG8TUJH

Re: Toggle Visibility

PostPosted: Sun Sep 04, 2011 10:44 pm
by BlueLight
miicas Wrote:Q.Q if then statements are what made me give up on learning java


Huh i picked them up very quickly and i didn't know anything about programming.

i don't know how much you know about programming in general.

Code: Select All Code
If(coolaid == true) { system.out.println("It seems you have coolaid. Now drink up");


basically is the boolean coolaid equals true than it will print out in the console whats said.

I try not to use them since they make code complex and hard to edit if you need to edit that block. but i understand if that have a use. Like in minecraft you could say if lava hits player call method "burst in to flames".

Re: Toggle Visibility

PostPosted: Fri Apr 27, 2012 8:22 am
by gootapparel
What are peoples opinons on the colour of helmets for visibility when stuck in holes?