Jump to content

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


peter wu
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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