Skip to main content
Participating Frequently
December 24, 2017
Answered

dispatchEvent

  • December 24, 2017
  • 4 replies
  • 494 views

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

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer kglad

    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.

    4 replies

    Legend
    December 25, 2017

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

    eval() - JavaScript | MDN

    kglad
    Community Expert
    Community Expert
    December 25, 2017

    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

    Gico62Author
    Participating Frequently
    December 25, 2017

    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();
    }

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    December 25, 2017

    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.