Skip to main content
Inspiring
November 10, 2017
Answered

not an object error

  • November 10, 2017
  • 1 reply
  • 363 views

In this code, a checkmark appears when each button is clicked. When all 3 buttons are clicked I want the continue arrow to appear. It is on stage, but invisible. I get an error "TypeError: undefined is not an object (evaluating 'this.continueArrow.visible = true')".

this.atmosphere_but.addEventListener("click", fl_ClickToGoToAndStopFromFrame208.bind(this));  var checks = 0;  function checkChecks() {      //alert(checks);      if (checks >=3) {            this.continueArrow.visible = true;        } }  function fl_ClickToGoToAndStopFromFrame208() {      this.gotoAndStop(208);      this.check1.visible = true;      checks = checks+1;      checkChecks();       }   this.crust_but.addEventListener("click", fl_ClickToGoToAndStopFromFrame209.bind(this));  function fl_ClickToGoToAndStopFromFrame209() {      this.gotoAndStop(209);      this.check2.visible = true;      checks = checks+1;      checkChecks(); }   this.mantle_but.addEventListener("click", fl_ClickToGoToAndStopFromFrame210.bind(this));  function fl_ClickToGoToAndStopFromFrame210() {      this.gotoAndStop(210);      this.check3.visible = true;      checks = checks+1;      checkChecks(); }  
This topic has been closed for replies.
Correct answer kglad

"this" isn't defined in checkChecks().

ie, pass a reference from your other functions where it is defined or define a variable that can be used in checkChecks.  the former:

function checkChecks(this_var){

//now use "this_var" instead of "this"

}

function yourotherfunctions(){

.

.

checkChecks(this);

}

////////////////////////

the later:

var this_var=this;

function checkChecks(){

//now use "this_var" instead of "this"

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 10, 2017

"this" isn't defined in checkChecks().

ie, pass a reference from your other functions where it is defined or define a variable that can be used in checkChecks.  the former:

function checkChecks(this_var){

//now use "this_var" instead of "this"

}

function yourotherfunctions(){

.

.

checkChecks(this);

}

////////////////////////

the later:

var this_var=this;

function checkChecks(){

//now use "this_var" instead of "this"

}

pbesongAuthor
Inspiring
November 10, 2017

that worked perfectly. thanks kglad! I'd have never figure that out.

kglad
Community Expert
Community Expert
November 10, 2017

you're welcome.

p.s. use console.log to debug and a browser with a developer option so you can see that output.  or just use alert() with any browser.