Jump to content

[Error] TypeError: 'undefined' is not an object (evaluating 'this.time.events')

peter wu

Recommended Posts

I am a new joiner and meet following issue need help, many thx.



I have following coding in my update: function( ){ } function,

 if (bid_ending_flag == true){  //countdown        console.log('[On update]:started.');        countdown_timer = 10;        timerEvent = this.time.events.loop(this.game.Timer.SECOND, this.updateTimer);

in my updateTimer function is like this:

updateTimer: function(){  countdown_timer -= 1;  if(countdown_timer === -1) {    this.time.events.remove(timerEvent);   <--error happened here    setTimeout(countDownText.destroy(), 1000);  } else {    countDownText.setText(countdown_timer);  <-- this worked properly  }},

Once bid_ending_flag is true, the countdown could be work count from 9 to 0, but 

the problem happened, always popup error message say  : [Error] TypeError: 'undefined' is not an object (evaluating 'this.time.events') in my updateTimer function. 


I have no idea and hope to get any expert's help. thanks advance again.

Link to comment
Share on other sites

Wherever you pass a function through as a callback, I recommend passing through a context as well...

In your case here, 'this' inside the updateTimer function is not the 'this' that you think it is.


Try this:

// Old code with no callback context...// timerEvent = this.time.events.loop(this.game.Timer.SECOND, this.updateTimer);// New code with callback context...timerEvent = this.time.events.loop(this.game.Timer.SECOND, this.updateTimer, this);
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...