Skip to main content
Cassidy Jean McAuliffe
Participating Frequently
February 2, 2022
Answered

How to have a pop-up close when you click on a different button

  • February 2, 2022
  • 2 replies
  • 1052 views

Each of these "people" are buttons (pictured). When you click the button, a pop up opens. When you click the button again it closes. I would also like the pop up to close if you click a different button on the page. Is that possible?

 

I have it hosted here if you'd like to try it as is right now:

https://itch.io/embed-upload/4912301?color=333333

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

There are several ways to do this. Two of them would be:

 

1 - A single Movie Clip with each pop-up in different frames. As soon as the user taps/clicks a button, you send the Movie Clip to the corresponding frame. This strategy would function better if your pop-ups appear or disappear without animation.

 

2 - You can have the pop-ups as different Movie Clips and use a variable to save the current opened pop-up. In this way, when the user taps/clicks on the next, you close the previous stored in the variable, open the current and save the current in the same variable.

 

Please let us know if those make sense and if you need further assistance.

 

Regards,

JC

2 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
February 3, 2022

Hi.

 

There are several ways to do this. Two of them would be:

 

1 - A single Movie Clip with each pop-up in different frames. As soon as the user taps/clicks a button, you send the Movie Clip to the corresponding frame. This strategy would function better if your pop-ups appear or disappear without animation.

 

2 - You can have the pop-ups as different Movie Clips and use a variable to save the current opened pop-up. In this way, when the user taps/clicks on the next, you close the previous stored in the variable, open the current and save the current in the same variable.

 

Please let us know if those make sense and if you need further assistance.

 

Regards,

JC

Cassidy Jean McAuliffe
Participating Frequently
February 3, 2022

Hi JC,

 

Thank you so much for your reply. I am very new to animate and have created this by watching tutorials that walk you through the process step by step. I've uploaded a video that shows my process of making a button and pop-up here:

https://drive.google.com/file/d/1gvZkgvdTDinrYbUKW7IvNM2mvj-CmPvf/view?usp=sharing

 

Are there any tutorials you can point me to that show how to go about either of the 2 options you've outlined above?

 

Thanks so much for your help.

Cassidy

JoãoCésar17023019
Community Expert
Community Expert
February 4, 2022

Thanks a lot, Cassidy, for the video.

 

Here is a sample that hopefully will help you to get started:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/pop_ups

 

The main code is this:

var root = this;

root.callPopUp = function(e)
{
	root.popUps.gotoAndStop(e.target.name);
};

root.dismissPopUp = function(e)
{
	if (e.target.name === "closeButton" || e.target.name === "hit")
		root.popUps.gotoAndStop(0);
};

root.person0.on("click", root.callPopUp);
root.person1.on("click", root.callPopUp);
root.person2.on("click", root.callPopUp);
root.person3.on("click", root.callPopUp);
root.person4.on("click", root.callPopUp);
root.popUps.on("click", root.dismissPopUp);
root.hit.on("click", root.dismissPopUp);

 

I hope this helps.

 

Regards,

JC

Cassidy Jean McAuliffe
Participating Frequently
February 2, 2022

Or if this is easier, close pop-up when click outside it.