4 Replies Latest reply on Dec 25, 2017 2:40 PM by kglad

    dispatchEvent

    Gico62 Level 1

      Hi, I don't undertstand why this is working

      main script firts frame :

      this.on("gameover", function() {

           this.gotoAndStop('gameover');

      });

      with this in a clip :

      this.dispatchEvent("gameover", true);

       

      but this function in the main script is not working:

      function eval(){

         if(clics==maxClics){

          this.dispatchEvent("gameover", true);

         }

      }

       

      thanks and merry christmas

        • 1. Re: dispatchEvent
          kglad Adobe Community Professional & MVP

          clics may not be defined (in that function)

          maxClics may not be defined (in that function)

          this may not be defined in that function

          and you may not be dispatching from the correct timeline

          • 2. Re: dispatchEvent
            ClayUUID Adobe Community Professional

            There's already a global "eval" function in JavaScript. You can't override it.

             

            eval() - JavaScript | MDN

            • 3. Re: dispatchEvent
              Gico62 Level 1

              Hi, first i changed the function name as  ClayUUID suggested it. with no better success.

               

              For kglad remarq : this is the whole code, all in the first frame, first level:

               

              this.on("gameover", function() {

                   this.gotoAndStop('gameover');

              });

               

              function  evalscore(){
                 if(clics==maxClics){
                  this.dispatchEvent("gameover", true);
                 }
              }

              function obj_bon(obj) {

                  score++;

                  clics++;
                  evalscore();
              }

              • 4. Re: dispatchEvent
                kglad Adobe Community Professional & MVP

                so you can rule out the last option if that's all on the same timeline.  these three possible issues remain:

                 

                clics may not be defined (in that function)

                maxClics may not be defined (in that function)

                this may not be defined in that function

                 

                 

                use console.log to debug.