Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-14-2012, 03:53 PM   #1
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default Visible / invisible movieclip

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.

Code:
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;
	 }
}
Grobi93 is offline   Reply With Quote
Old 03-14-2012, 04:07 PM   #2
5TonsOfFlax
.as-hole
 
Join Date: Jan 2010
Posts: 781
Default

== != =
5TonsOfFlax is offline   Reply With Quote
Old 03-14-2012, 07:43 PM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,829
Send a message via Skype™ to henke37
Default

People usually screw this up in the other direction. You are using comparisons where you wanted assignments.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 03-14-2012, 10:45 PM   #4
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default

Thanks for your replies. It wasn't working with = instead of ==, so I have just switched to ActionScript 2.
Grobi93 is offline   Reply With Quote
Old 03-14-2012, 11:02 PM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,829
Send a message via Skype™ to henke37
Default

That's a silly reason to switch.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 03-15-2012, 01:42 AM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

Assuming you are trying to toggle the visibility (true/false) of any DisplayObject (bitmap, movieclip, sprite, textfield, shape, etc...) located at index 0 within kerdesek_mc.
You don't need an if/else statement for toggling between two states.
ActionScript Code:
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 {     kerdesek_mc.getChildAt(0).visible = !kerdesek_mc.getChildAt(0).visible; }
[afz]snickelfitz is offline   Reply With Quote
Old 03-15-2012, 09:18 AM   #7
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default

Thanks for your answers.

PS: I have switched to AS2 because I like the idea, that you can give AS scripts directly to objects.
Grobi93 is offline   Reply With Quote
Old 03-15-2012, 09:49 AM   #8
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

AS2 frame scripting is perfectly fine for what you're trying to do, but your reasoning for switching from AS3 to AS2 is fallacious.
[afz]snickelfitz is offline   Reply With Quote
Old 03-15-2012, 04:18 PM   #9
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,811
Send a message via AIM to abeall
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
AS2 frame scripting is perfectly fine for what you're trying to do, but your reasoning for switching from AS3 to AS2 is fallacious.
I think he means the fact that you cannot attach instance code in Flash Pro. This is a challenge in AS3/Flash Pro that has no simple workaround for everyone.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter

Last edited by abeall; 03-15-2012 at 04:22 PM.
abeall is online now   Reply With Quote
Old 03-15-2012, 05:30 PM   #10
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

The code in post #1 would have failed in AS2 as well.
[afz]snickelfitz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:27 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.