4 Replies Latest reply on Jun 14, 2017 7:08 PM by ClayUUID

    Test duplicates functions upon restart

    Marampazú Level 1

      I am developing a test that will give the user several opportunities to complete it.

      Let's say you have to answer at least 7 correct answers out of a total of 10.

      The exercise works, only that when I reboot to execute another attempt, it repeats the functions to me twice and so on.

      If I do it for the third time, repeat the functions 3 times.

      I've reviewed the code again, but I do not find it to be failing.

      Attach the file also if it serves someone as the basis of an exercise.

      I have developed some exercises in Animate but something that has happened to me several times is that if I call to call a function in a main mc from a nested one, it executes the function but repeats it increasing once every one that is executed.

      Thanks for your help. Stay tuned.



      By the way, how do I attach files to this message? I have a wetransfer, if there is another way, let me know.


        • 1. Re: Test duplicates functions upon restart
          kglad Adobe Community Professional & MVP

          you can't attach files to messages in the adobe forums.


          what do you mean by "..it repeats the functions.."?


          do you mean some functions execute more than once?  if so, you're probably adding the same listener repeatedly.

          2 people found this helpful
          • 2. Re: Test duplicates functions upon restart
            Marampazú Level 1

            Thanks for answering!

            I have already placed a removeEventListener ("click", MyFunctionName) to prevent the listener from being added again on my second attempt. I did not know that this was what was happening, every time I repeated the exercise a new listener was added to the same button (even if it was with the same functions).
            With that line working, however I realized that all the buttons in my exercise suffer from the same problem. Obviously this is not perceptible since their interaction does not send alerts or sum points, however I would like to solve it.
            The question would be: what is the best way to do this? I tried placing the following line: this.removeAllEventListeners (); At the same point I mentioned but it did not work. Which would be the right place to place this call since I have a main movie and several nested. Ideally, you should turn them all off at the same time when you restart the exercise.

            Again, thank you for responding. Sometimes it's complicated for those of us who are not programming experts but we like (I'm actually a graphic designer).


            • 3. Re: Test duplicates functions upon restart
              kglad Adobe Community Professional & MVP

              removeEventListener works.


              you just have to be careful if you use yourfunction.bind(this) and you should apply it like so:


              var yourfunction_bind = yourfunction.bind(this);






              instead of trying to use what you might think would work:



              whatever.removeEventListener('click',yourfunction.bind(this));  // will fail because yourfunction.bind() is not the same here and two lines down



              • 4. Re: Test duplicates functions upon restart
                ClayUUID Adobe Community Professional

                In situations where it's just the one listener being adding to an object, you don't even need the extra variable. Just don't add the listener again if it already has one.


                if (!whatever.hasEventListener("click")) {

                     whatever.addEventListener("click", yourfunction.bind(this));