Skip to main content
Known Participant
June 18, 2012
Answered

Is there a way to have the ActionScript in a MovieClip affect the actions in other MovieClips?

  • June 18, 2012
  • 1 reply
  • 1394 views

Hey everyone, I need some help being pointed in the right direction. What I am trying to do is write ActionScript in a nested movieClip and have it affect the movie clip it is nested in, or even the main timeline. An example would be:

MovieClip Instance "B" is nested inside MovieClip Instance "A" which is on the Main Timeline. I want it so when the user clicks Button "1" in MovieClip "B" to stop the timeline in MovieClip "A", but if the user clicks Button "2" in MovieClip "B" it will make the Main Timeline play.

If someone can get me started with what I am trying to accomplish, I can most likely research the rest.

Thanks in advance!

-DJ

This topic has been closed for replies.
Correct answer Ned Murphy

Hey Ned,

Your answer was great, but I do have one instance where a keyframe at a certain time in a movie clip needs to talk to the main timeline to tell it to play a movie clip. Anyway to reference the root timeline from a movie clip??

Ex. If MovieClip A reaches frame 5, then have MovieClip C in the main timeline play.

-DJ


You can use:  MovieClip(root).mcNameEtc.play();

although there is a more oop correct way of having children talking to parents.  What you do is have the child dispatch an event.  Just like the other listeners, in the main timeline an event listener is assigned to the child movieclip to listen for that custom event and that in turn calls the event handler to react to the event.

1 reply

Ned Murphy
Legend
June 18, 2012

If you write the code in the main timeline it will be easier for you to keep track of as far as targeting goes.  You can assign the listeners to the mcB by targeting it thru mcA...

mcA.mcB.btn1.addEventListener(MouseEvent.CLICK, stopA)

function stopA(evt:MouseEvent):void {

     mcA.stop();

}

and similarly for the play functionality

Known Participant
June 18, 2012

Thanks! I'll use this methood instead.

Ned Murphy
Legend
June 18, 2012

You're welcome