Skip to main content
Participant
May 16, 2024
Answered

Multiple buttons to visit webpage opens 1000 tabs

  • May 16, 2024
  • 3 replies
  • 540 views

Greetings, 

 

I would like some help in adobe animate , I create an animation with multiple buttons which each buttons visit different webpages. 

 

However, when I publish the project and click buttons open for me 1000 tab in browser for single tab. 

 

Could you please advice and help how to make sure it open in single click only once, every time press on the button. 

 

Looking forward to hear your solutions

 

 

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

    Hi.

     

    Usually this happens when the same button receives multiple event listeners of the same type when a frame is revisited.

     

    One approach I like to use is to check for a custom boolean flag. Like this:

    if (!this.started)
    {
        // code to add listeners
        this.started = true;
    }

     

    This ensures that the listeners are added only once.

     

    But if you show us your code, we may be able to help you better.

     

    Regards,

    JC

    3 replies

    Participant
    July 18, 2024

    THANK YOU so much for this @JoãoCésar! You saved me!!!

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 18, 2024

    No problem!

     

    Good to know that the answer was helpful.

    human2024Author
    Participant
    May 19, 2024

    Thank you @JoãoCésar17023019 

     

    I was confused bit with your answer as I saw on the net other answer 

     

    if (!this.started)
    {
      this.btn1.addEventListener("click", fl_ClickToGoToWebPage_3);
    
    function fl_ClickToGoToWebPage_3() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.ac_h_btn.addEventListener("click", fl_ClickToGoToWebPage_10);
    
    function fl_ClickToGoToWebPage_10() {
    	window.open("https://www.google.com", "_blank");
    }
    
    this.s_h_btn2.addEventListener("click", fl_ClickToGoToWebPage_26);
    
    function fl_ClickToGoToWebPage_26() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.h_g.addEventListener("click", fl_ClickToGoToWebPage_20);
    
    function fl_ClickToGoToWebPage_20() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.O_sy_meta.addEventListener("click", fl_ClickToGoToWebPage_21);
    
    function fl_ClickToGoToWebPage_21() {
    	window.open("https://yahoo.com", "_blank");
    }
    
    this.e_h_btn.addEventListener("click", fl_ClickToGoToWebPage_4);
    
    function fl_ClickToGoToWebPage_4() {
    	window.open("https://bing.com", "_blank");
    }
        this.started = true;
    }

     

    And it worked , so far so good, I left the page open for while and doesn't open up tab. 

     

     

     

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 20, 2024

    Nice!

     

    You're welcome.

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 16, 2024

    Hi.

     

    Usually this happens when the same button receives multiple event listeners of the same type when a frame is revisited.

     

    One approach I like to use is to check for a custom boolean flag. Like this:

    if (!this.started)
    {
        // code to add listeners
        this.started = true;
    }

     

    This ensures that the listeners are added only once.

     

    But if you show us your code, we may be able to help you better.

     

    Regards,

    JC

    human2024Author
    Participant
    May 19, 2024

    I adjust code to this and stop working 

    if (!this.btn1.addEventListener("click", fl_ClickToGoToWebPage_3))
    {
       function fl_ClickToGoToWebPage_3() {
    	window.open("https://adobe.com", "_blank");
    }
    }
    
    if (!this.ac_h_btn.addEventListener("click", fl_ClickToGoToWebPage_10))
    {
      
    function fl_ClickToGoToWebPage_10() {
    	window.open("https://www.google.com", "_blank");
    }
    }

     

    my original code is this 

     

    this.btn1.addEventListener("click", fl_ClickToGoToWebPage_3);
    
    function fl_ClickToGoToWebPage_3() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.ac_h_btn.addEventListener("click", fl_ClickToGoToWebPage_10);
    
    function fl_ClickToGoToWebPage_10() {
    	window.open("https://www.google.com", "_blank");
    }
    
    this.s_h_btn2.addEventListener("click", fl_ClickToGoToWebPage_26);
    
    function fl_ClickToGoToWebPage_26() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.h_g.addEventListener("click", fl_ClickToGoToWebPage_20);
    
    function fl_ClickToGoToWebPage_20() {
    	window.open("https://adobe.com", "_blank");
    }
    
    this.O_sy_meta.addEventListener("click", fl_ClickToGoToWebPage_21);
    
    function fl_ClickToGoToWebPage_21() {
    	window.open("https://yahoo.com", "_blank");
    }
    
    this.e_h_btn.addEventListener("click", fl_ClickToGoToWebPage_4);
    
    function fl_ClickToGoToWebPage_4() {
    	window.open("https://bing.com", "_blank");
    }