Skip to main content
Participant
August 6, 2021
Question

Listener breaks on Loop

  • August 6, 2021
  • 1 reply
  • 186 views

Finally getting back into web banners. I made a banner with a dynamically created disclaimer at the end. (clicking on the 'important info' button attaches a new div to the stage that can scroll the really long disclaimer).

 

The timeline is set to loop after a few seconds. Once it loops, though, the close button of the disclaimer no longer works. Any idea why?

 

I've uploaded a reduced file with the issue.

 

can access the .fla file here:

https://www.dropbox.com/s/w3g6b7nzx60asba/vanilla_Disclaimer_test.zip?dl=0

 

(Forum will not allow me to attach the file directly for some reason)

 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    August 7, 2021

    you're probably re-adding that listener creating more and more copies of that div each time you enter that frame.

     

    prevent that by using:

     

    if(!this.alreadyExecuted){

    //add your listener here

    this.alreadyExecuted = true;

    }

    Participant
    August 10, 2021

    Thank you.

     

    It looks like the issue was actually with the function creating the listener that creates the popup div and not the one adding the listener to the close button. (It's funny that the div-creator button still worked, but not the close button!) I used your check on that first function and it seems to work.

     

    I'm still so confused by how variables work locally v globally in Animate!

    kglad
    Community Expert
    Community Expert
    August 10, 2021

    you're welcome.

     

    the issue was you were probably creating multiple objects with the same reference because of the multiple listeners and the close button couldn't reference multiple objects with the same reference.