Copy link to clipboard
Copied
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.
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();
}
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks to @Colin Holgate too ... sorry 🙂
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
what i mean is ... I would insert the script inside each movieclip layer and not on the main timeline layer
Copy link to clipboard
Copied
each movieclip including the main timeline has, at least, one layer (and can have up to 1600, i believe).
it doesn't make sense to add the same thing to every layer in any movieclip/main timeline. it also doesn't make sense to add the same thing to every movieclip and the main timeline.
if you want to create a "close this popup window" object, add it the popup's main timeline and if you then add other objects that cover the entire stage, make sure they are in a layer below the "close" object so it's always visible and available to be clicked. then add your code to the main timeline.
Copy link to clipboard
Copied
First of all.. thanks for your patience.
WHat i have done is created a simple button 'Close_popup_btn' inside of a movieclip 'popup_mc'. .
Then I have placed this code :
this.Close_popup_btn.addEventListener("click", fl_ClickToHide_3.bind(this));
function fl_ClickToHide_3()
{
this.popup_mc.visible = false;
}
... in the actions layer on the main timeline of my project. It didnt work .
Am I totally going the wrong way with it.? Thankyou in advance .
Kind regards.
Rich
Copy link to clipboard
Copied
oh.
if your popup really isn't a popup but a movieclip that's added to the main window, then that code is ok, but better would to use this.popup_mc.parent.removeChild(this.popup_mc) and when you want it to reappear to use whatever_parent_mc.addChild(this.popup).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thankyou. Thats much appreciated.
Im learning a lot 🙂
Kind regards .
Copy link to clipboard
Copied
you're welcome.