函数外为什么停不了?clearInterval
private countDownTimer = 0;
private timeControl(second) {
if (second > 0) {
this.countDownTimer = egret.setTimeout(()=>{
}, this, 1000);
this.countDownTimer = egret.setInterval(function () {
if (second > 0 && this.bCanSelectFreeGame) {
second--;
// console.log('secound:', second);
let str: string = Utils.replaceString(Config.language['freeGameCountDown_' + Config.lang], [second]);
MainGameView.instance.changeGameTip(str);
if (second <= 0) {
// console.log("停止计时");
clearInterval(this.countDownTimer);//倒计时结束停止有效
let str: string = Utils.replaceString(Config.language['mainGame016_' + Config.lang]);
MainGameView.instance.changeGameTip(str);
}
}
}, this, 1000);
}
}
private onOpenButton(evt: egret.Event) {
let self = this;
clearInterval(this.countDownTimer);//倒计时还未结束时点击按钮停止无效?
}