Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript: Why I can't clearTimeout in my object behavior?
    text
    copied!<p>I have been solving this for many hours but I don't know why I can't solve it. I have the following code:</p> <pre><code>var Timer_Tick; var Game_Engine = { //Set the min and sec of the timer by default is 2 min min:1, sec:60, star_count: 0, tongue_count: 0, time: '', star1: '', star2: '', star3: '', star_bar: '', tongue_bar: '', frog: '', bug: '', flower: '', Timer: function () { //Start Timer var that = this; var stop = function () { that.stopTimer(); }; Timer_Tick = setTimeout(function () { var Time = new Date(0, 0, 0, 0, that.min, that.sec--).toTimeString().slice(3,8); that.time.text = Time; console.log(that.min + ':' + that.sec); if (that.min === 1 &amp;&amp; that.sec === 40) { that.bug.gotoAndPlay('take_photo'); that.flower.onPress = null; stop(); } else if (that.min === 1 &amp;&amp; that.sec === -60) { that.stopTimer(); //clearTimeout(Timer_Tick); that.time.text = '00:00'; createjs.Tween.get(that.bug, { loop: false }).to({ y: that.bug.y + 100 }, 400, createjs.Ease.linear); setTimeout(function () { that.bug.gotoAndPlay('bite'); setTimeout(function () { that.flower.gotoAndPlay('broken_flower'); that.frog.gotoAndPlay('lose'); }, 200); createjs.Tween.get(that.bug, { loop: false }).wait(500).to({ x: 200, y: -100 }, 6000, createjs.Ease.linear); }, 400); } that.Timer(); }, 100); }, stopTimer: function () { //Pause or stop Timer clearTimeout(Timer_Tick); } }; </code></pre> <p>I already put the <code>debugger</code> to find out that my event is fired or not. The result is it is fired correctly as expect but the Timer doesn't stop and keep going forever. Can anyone help me I really need your help now. I'm new to javascript :). Thanks in Advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload