peter wu Posted November 23, 2015 Share Posted November 23, 2015 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 More sharing options...
shohan4556 Posted November 23, 2015 Share Posted November 23, 2015 have you tried this.game.time.events.remove(.....); ? Link to comment Share on other sites More sharing options...
XekeDeath Posted November 23, 2015 Share Posted November 23, 2015 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); peter wu and in mono 2 Link to comment Share on other sites More sharing options...
peter wu Posted November 25, 2015 Author Share Posted November 25, 2015 Thanks buddies. when I added 'this' right after this.updateTimer in timerEvent, the problem is missing. seems a lot of unknown and more knowledge required for me. Very much appreciated for your kind help. Link to comment Share on other sites More sharing options...
Recommended Posts