Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

dispatchEvent

Community Beginner ,
Dec 24, 2017 Dec 24, 2017

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

401
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 25, 2017 Dec 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.

Translate
Community Expert ,
Dec 24, 2017 Dec 24, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 25, 2017 Dec 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();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2017 Dec 25, 2017
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 25, 2017 Dec 25, 2017

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

eval() - JavaScript | MDN

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines