Toggle Visibility

A place for tutorials on how to get the most out of Flash

Toggle Visibility

Postby kojiro » Fri Sep 02, 2011 4:24 am

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?
kojiro
 
Joined: Sat Jul 16, 2011 4:35 am

Re: Toggle Visibility

Postby BlueLight » Fri Sep 02, 2011 7:23 am

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
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Toggle Visibility

Postby GolanTrevize » Fri Sep 02, 2011 12:03 pm

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).
Current project: Dark moon (Artists needed)
User avatar
GolanTrevize
 
Joined: Wed Jul 20, 2011 3:32 pm

Re: Toggle Visibility

Postby BlueLight » Fri Sep 02, 2011 1:14 pm

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.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Toggle Visibility

Postby kojiro » Fri Sep 02, 2011 6:33 pm

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
kojiro
 
Joined: Sat Jul 16, 2011 4:35 am

Re: Toggle Visibility

Postby GolanTrevize » Fri Sep 02, 2011 8:11 pm

At as2 it would be like :

glasses._alpha = 0

I hope it works at AS3
Current project: Dark moon (Artists needed)
User avatar
GolanTrevize
 
Joined: Wed Jul 20, 2011 3:32 pm

Re: Toggle Visibility

Postby kojiro » Sat Sep 03, 2011 3:18 am

didnt work just turns invisible and is still a button but wont comeback no matter how many times i click it
kojiro
 
Joined: Sat Jul 16, 2011 4:35 am

Re: Toggle Visibility

Postby BlueLight » Sat Sep 03, 2011 4:34 am

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.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Toggle Visibility

Postby miicas » Sun Sep 04, 2011 8:15 pm

Q.Q if then statements are what made me give up on learning java
chaotic god: "I AM ALL POWERFUL"
Miicas:*stops releasing chaos energy * "what now bitch?"
User avatar
miicas
 
Joined: Sun Aug 28, 2011 6:13 pm
Location: with ceiling cat ... watching you masterbate

Re: Toggle Visibility

Postby GolanTrevize » Sun Sep 04, 2011 9:18 pm

just change the lines


if( glasses._alpha == 0){
glasses._alpha = 100
}else{
glasses._alpha = 0
}
Current project: Dark moon (Artists needed)
User avatar
GolanTrevize
 
Joined: Wed Jul 20, 2011 3:32 pm

Re: Toggle Visibility

Postby kojiro » Sun Sep 04, 2011 9:50 pm

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
kojiro
 
Joined: Sat Jul 16, 2011 4:35 am

Re: Toggle Visibility

Postby BlueLight » Sun Sep 04, 2011 10:44 pm

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".
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Toggle Visibility

Postby gootapparel » Fri Apr 27, 2012 8:22 am

What are peoples opinons on the colour of helmets for visibility when stuck in holes?
gootapparel
Newly Registered
 
Joined: Fri Apr 27, 2012 8:21 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users