Skip to main content
Inspiring
January 11, 2022
Answered

Reset button for movieclip

  • January 11, 2022
  • 3 replies
  • 1047 views

Hi All. Hope you are well.

 

Ive had a good search through the forums but havent found quite what I need. Im very new to Animate.

 

Basically I have a button on my main timeline, when I click , a popup window appears and a movieclip plays . It plays to the end and stops. Then when I click the button again the popup dissapears. Heres where Im having a problem. If I now click the button again , the popup re-appears but its still at the last frame of the movieclip. How can I get it to re-appear and play from the start again ?

 

Thanks in advance for any help on this.

 

Kind regards

 

Rich.

 

 

    This topic has been closed for replies.
    Correct answer richardj60140276

    Hi .. I just realised that I may have caused confusion by calling the movieclip a popup. Would you be ok with having a look at my file if I sent you a simple version of what im trying to do ? From your last Answer I cant work out where that code is supposed to go.


    Just an update so I dont take up anymore of your time. I figured it out eventually :).

     

    I used : 

     

    var _this = this;
    _this.close_btn.on('click', function(){

    _this.gotoAndStop(1);
    });

     

    Inside the movieclip .

     

    It worked perfectly. Thanks again for your help . Im slowly starting to understand it more.

     

    Kind regards

    Have a nice day.

     

    3 replies

    Inspiring
    January 14, 2022

    Something ive been trying to add to my popup windows .. is a close popup 'X' button . Would I add the button and script for these inside each popup window movieclip ? 

     

    Thankyou in advance.

    Kind regards.

     

    Rich

    kglad
    Community Expert
    January 14, 2022

    yes, that makes the most sense because you would assume the user is looking at the popup at the time they would like to close it.  it would not be expected that you would have to select the main html to close the popup.

    kglad
    Community Expert
    January 17, 2022

    Just an update so I dont take up anymore of your time. I figured it out eventually :).

     

    I used : 

     

    var _this = this;
    _this.close_btn.on('click', function(){

    _this.gotoAndStop(1);
    });

     

    Inside the movieclip .

     

    It worked perfectly. Thanks again for your help . Im slowly starting to understand it more.

     

    Kind regards

    Have a nice day.

     


    the 2nd frame of your movieclip must contain nothing visible on stage for that to appear to work.  ie, it doesn't remove the movieclip, but the user won't see anything on stage if that's the case.

     

    better (especially if you're using addChild to add your movieclip) would be to use the code i suggested before:

     

    var _this = this;
    _this.close_btn.on('click', function(){

    _this.parent.removeChild(_this);
    });

     

    or if, from the main timeline, you're using this.popup_mc.gotoAndStop(somewhere) or this.popup_mc.gotoAndStop(somewhere), your code is better.

    kglad
    Community Expert
    January 11, 2022

    assuming this is a canvas project:

     

    in your click listener function is popupF, your popup movieclip is popup_mc  and your triggering button is popup_btn:

     

    this.popup_mc.visible = false;

    this.popup_btn.addEventListener("click",popupF.bind(this))

     

    function popupF(){

    if(this.popup_mc.visible){

    this.popup_mc.visible=false;

    this.popup_mc.gotoAndStop(0);

    } else {

    this.popup_mc.visible = true;

    this.popup_mc.play();

    }

    Inspiring
    January 12, 2022

    Hi Kglad.

    Just a quick message to say Thanks very much for your help. That was exactly what I needed . Worked a treat. 

     

    One quick thing for anyone else reading the solution... there was a missing close bracket at the end so just needed to add that . 

     

    Thanks again my friend. Have a great day.

     

    Kind regards

    Rich

    kglad
    Community Expert
    January 12, 2022

    you're welcome.

     

    p.s. @Colin Holgate and i posted at the same time and the code i showed is equivalent to his last suggestion.

    Colin Holgate
    Inspiring
    January 11, 2022

    It may be that you're using HTML5 Canvas, and with those movieclips remember their last state. Going to somewhere that the movieclip isn't around, and coming back again, will show the frame it had reached the first time. It's different with AS3, then the movieclip will start from the beginning.

    You could either do a new movieclip each time with code, and remove and null it when you're done. Or you could tell it to gotoAndPlay(0) when you show it each time.