Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-27-2007, 07:12 PM   #1
Fear_of_AS
Registered User
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 17
Unhappy How do I make a button invisible?

Ok, this question is quite nooby.

I have a series of buttons that I want to cycle through and make them invisible/visible. My code works perfectly fine for making movie clips invisible, but doesn't seem to work for buttons.

(I have a lot more code, but I'll strip away everything else that's irrelevant. here it is: )

[clarification: checkX and crossX are MovieClips. explanationX is the Button. I tried casting it as a movie (I think), but got the following error message on execution:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-315()

]

ActionScript Code:
CheckAnswers2.addEventListener(   MouseEvent.MOUSE_UP,   function(evt:MouseEvent):void {       if(incomplete!=true){            for(i=0; i<5; i++){               var target3:MovieClip = getChildByName("check"+(i+1)) as MovieClip;           var target4:MovieClip = getChildByName("cross"+(i+1)) as MovieClip;           var target7:MovieClip = getChildByName("explanation"+(i+1)) as MovieClip;           target4.visible=true;           target3.visible=false;           target7.visible=true;         }     }     } );

Last edited by Fear_of_AS; 07-27-2007 at 07:18 PM.
Fear_of_AS is offline   Reply With Quote
Old 07-27-2007, 07:27 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

sounds like you got one of (some?) your naming wrong. Trace your movie clip references and see which ones end up null
__________________
(6)
senocular is offline   Reply With Quote
Old 07-27-2007, 07:29 PM   #3
jsimpson
Spontaneous Flasher
 
jsimpson's Avatar
 
Join Date: Nov 2006
Posts: 379
Send a message via AIM to jsimpson
Default

Quote:
var target7:MovieClip = getChildByName("explanation"+(i+1)) as MovieClip;
For one if you didn't cast it as a MovieClip in this statement you'd get an error for trying to put something other than a movie clip inside of target7, which is only a movieclip.Try using "target7:Button", and remove the "as MovieClip" from the end of the line. Visible is a property of all display objects so I believe it should work after that.

EDIT: After reading Senocular's post, the error says a null object which means there is something else wrong besides just the type. Check to make sure your names are correct. Try commenting out the loop and make sure the error is inside the loop.

Last edited by jsimpson; 07-27-2007 at 07:34 PM.
jsimpson is offline   Reply With Quote
Old 07-27-2007, 07:31 PM   #4
Fear_of_AS
Registered User
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 17
Default

senocular:

hmm, beg your pardon? :-)

you mean a typo in the name of the instance? because I double and triple checked all those names (cross/check/explanation).

or some kind of other name?
Fear_of_AS is offline   Reply With Quote
Old 07-27-2007, 07:33 PM   #5
Fear_of_AS
Registered User
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 17
Post

Quote:
Originally Posted by jsimpson View Post
For one if you didn't cast it as a MovieClip in this statement you'd get an error for trying to put something other than a movie clip inside of target7, which is only a movieclip.Try using "target7:Button", and remove the "as MovieClip" from the end of the line. Visible is a property of all display objects so I believe it should work after that.

Yeah, I just tried it, but the compiler returns (for some unknown to me reason):

1046: Type was not found or was not a compile-time constant: Button.
Fear_of_AS is offline   Reply With Quote
Old 07-27-2007, 07:54 PM   #6
jsimpson
Spontaneous Flasher
 
jsimpson's Avatar
 
Join Date: Nov 2006
Posts: 379
Send a message via AIM to jsimpson
Default

Sorry I just realized the Button class is the class of the button component in the component drop down menu... I'm not sure what the class type is... perhaps try it without defining the type..

ActionScript Code:
var target7= getChildByName("explanation"+(i+1));
jsimpson is offline   Reply With Quote
Old 07-27-2007, 08:04 PM   #7
Fear_of_AS
Registered User
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 17
Default

Quote:
Originally Posted by jsimpson View Post
Sorry I just realized the Button class is the class of the button component in the component drop down menu... I'm not sure what the class type is... perhaps try it without defining the type..

ActionScript Code:
var target7= getChildByName("explanation"+(i+1));

Great! It works!

Thanks a bundle.
Fear_of_AS 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
home button to make page change Pezmc ActionScript 1.0 (and below) 0 12-28-2006 03:13 PM
correct syntax make movie clip work as button Des_Nv ActionScript 1.0 (and below) 1 10-09-2006 10:44 PM
How to make a flash button that works like an html button cahill04 ActionScript 2.0 3 10-20-2004 09:14 PM
How make only a part of an animation as a button? Help please! mx-guest2004 Animation and Effects 5 06-01-2004 02:58 AM
Masking one movie clip from another Art Simple Stuff (Newbies) 5 09-02-2001 04:47 PM


All times are GMT. The time now is 07:42 AM.

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