Skip to main content
Inspiring
June 2, 2008
Answered

Simple Button to Control Movie Clip

  • June 2, 2008
  • 5 replies
  • 731 views
Hello,

I was relatively comfortable with AS 2.0, but am having a hard time warming up to 3.0. I feel that this should be something simple to find help online with, yet I'm finding it difficult to get a simple answer.

I have a button that is inside a movie clip within another movie clip:

mainMenu_mc > whoBtn_mc > whoButton

This button appears to work fine controlling a movie clip on the same timeline. This is the code so far (on an Actions frame in WhoBtn_mc):

whoButton.addEventListener(
MouseEvent.CLICK,
function(evt:MouseEvent):void {
whoGlow.gotoAndStop("click");

}
);


I have another movie clip on the main timeline that I would like to control with this button:

blackFadeBottom_mc

What would the code look like for this?

Any help is appreciated - Thank you.
This topic has been closed for replies.
Correct answer charleuts
Thanks kglad, that worked like a charm. I just wasn't sure of the syntax, this helps a lot.

Appreciate all the help.

5 replies

kglad
Community Expert
Community Expert
June 4, 2008
you're welcome.
charleutsAuthor
Inspiring
June 4, 2008
I'm not sure what you mean. My movie clip is intentionally stopped on frame one. I would like it to goto the next frame and play once my button is clicked...if I put this code on the timeline the button is on, I get the trace, but no response from the movie clip:

whoButton.addEventListener(
MouseEvent.CLICK,
function(evt:MouseEvent):void {
MovieClip(evt.currentTarget.root).blackFadeBottom_mc;
//I assume that the above makes my mc the event target
gotoAndPlay(2);
trace("whoButton trace works");
}
);

What am I missing? I appreciate your patience!

Thanks,

Chuck
kglad
Community Expert
Community Expert
June 4, 2008
:

charleutsAuthorCorrect answer
Inspiring
June 4, 2008
Thanks kglad, that worked like a charm. I just wasn't sure of the syntax, this helps a lot.

Appreciate all the help.
kglad
Community Expert
Community Expert
June 4, 2008
use gotoAndPlay() applied to your movieclip
kglad
Community Expert
Community Expert
June 3, 2008
that must be placed somewhere that has access to blackFadeBottom_mc. so, where you place it depends on where and when you create your blackFadeBottom_mc movieclip.
charleutsAuthor
Inspiring
June 4, 2008
Thanks, I was able to place the code on the main timeline and get a trace when I clicked on the movie clip instance itself. I probably didn't explain what I was trying to do very well, so I apologize.

What I need to do is to control this movie clip that is physically placed on the main timeline (fadeBlackBottom) with the button that is buried under two other movie clips (mainMenu_mc>whoBtn_mc>whoBtn).

I would like the whoBtn to tell the fadeBlackBottom movie clip to (what used to be) _root.fadeBlackBottom.gotoAndPlay("play"); This will drop down a box that will contain the content of my 'Who' link.

How can I accomplish this?

Thanks again,

Chuck

kglad
Community Expert
Community Expert
June 4, 2008
:

kglad
Community Expert
Community Expert
June 2, 2008
you can use the root property of your button (cast as a movieclip) to reference the main timeline. if you want to reference a movieclip on the main timeline, you can use dot notation just like you did in as2:

blackFadeBottom_mc.addEventListener(
MouseEvent.CLICK,
function(evt:MouseEvent):void {
// MovieClip(evt.currentTarget.root).yourmovieclip

}
);
charleutsAuthor
Inspiring
June 3, 2008
As always kglad, thanks for the quick response and guidance.

I am a little unclear as to where to put this code exactly. Does this go in the same frame I have my other existing button code?

I keep getting the 'Access of undefined property blackFadeBottom_mc'

...this is what I tried. I put this in the same actions frame I have the other button code.

blackFadeBottom_mc.addEventListener(
MouseEvent.CLICK,
function(evt:MouseEvent):void {
MovieClip(evt.currentTarget.root).blackFadeBottom
gotoAndPlay("play");
trace("this works");
}
);

Thanks!