Skip to main content
Participant
October 26, 2017
Question

Replay button inside movieclip to replay entire animation

  • October 26, 2017
  • 2 replies
  • 343 views

Hi, my main stage consists of a single frame with different movieclips, each with different frame starting and ending positions, and of course a stop. The last one contains a replay button; on click I want it to replay every movie clip again, starting with the 1st one. I know that I have to set it up so each movie clip is restarted, but I'm at a loss on how to make it replay from the 1st movieclip since the button is inside the last one. I know an easy solution is to move the buttons to the main stage, but I'd like to learn how to set it inside a movieclip. Thank you in advance for the help.

This topic has been closed for replies.

2 replies

Ned Murphy
Legend
October 26, 2017

Another easy solution is to move all of the code to the main stage and target the movieclips from there, including the code that is used for the buttons in the last one.

lastmovieclip.addEventListener(MouseEvent.CLICK, restartAll);

function restartAll(evt:MouiseEvent):void {

        movieclip1.gotoAndPlay(1);

        movieclip2.gotoAndPlay(1);

        etc...

}

kglad
Community Expert
Community Expert
October 26, 2017

parent.movieclip1.gotoAndPlay(1);

parent.movieclip2.gotoAndPlay(1);

etc

atomizenAuthor
Participant
October 26, 2017

I tried setting the button Actionscript like this

replay.addEventListener(MouseEvent.CLICK, fl_ClickToRestart);

function fl_ClickToRestart(event:MouseEvent):void

{

parent.congrats_clip.gotoAndPlay(1);

parent.you_clip.gotoAndPlay(1);

parent.absol_clip.gotoAndPlay(1);

parent.nothing_clip.gotoAndPlay(1);

parent.viruswin_clip.gotoAndPlay(1);

}

and I got this error 5 times: "1119: Access of possibly undefined property ____ through a reference with static type flash.display:DisplayObjectContainer."

I googled some more, and I got it to work like this:

replay.addEventListener(MouseEvent.CLICK, fl_ClickToReplay);

function fl_ClickToReplay(event:MouseEvent):void

{

MovieClip(parent).congrats_clip.gotoAndPlay(1);

MovieClip(parent).you_clip.gotoAndPlay(1);

MovieClip(parent).absol_clip.gotoAndPlay(1);

MovieClip(parent).nothing_clip.gotoAndPlay(1);

MovieClip(parent).viruswin_clip.gotoAndPlay(1);

}

Thank you both nonetheless, it was learning about the parent function what helped me!

kglad
Community Expert
Community Expert
October 26, 2017

you're welcome.