Я пытаюсь остановить setTimeout кнопкой в моей игре, но когда я нажимаю на кнопку, я возвращаюсь в меню, и таймер продолжается. Может кто-нибудь мне помочь?отменить timeOut в JavaScript с помощью кнопки
P.s. Я резаным а, много кода в середине, чтобы сделать его меньше
this.stop();
///////////////////////////////////////////////////////////////////////////////////////////////////////
// gestion du temps
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.leTimeOut = window.setTimeout(punir.bind(this), 31000);
this.lInterval = window.setInterval(afficherTemps.bind(this), 1000);
/////////////////////////
Cutted section
////////////////////////
console.info("!!! "+nbMatchs+" !!!");
this.txtItems.text = ""+(6-nbMatchs);
if(nbMatchs == 6){
window.clearTimeout(this.leTimeOut);
this.gotoAndStop("FinNiveau1");
}
return bonnePosition;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction pour lancer la punition
///////////////////////////////////////////////////////////////////////////////////////////////////////
function punir(evt){
console.log("temps écoulé");
this.gotoAndStop("EchecNiveau1");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction d'affichage du temps
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.txtTimer.text = "29";
function afficherTemps(evt){
this.txtTimer.text = parseInt(this.txtTimer.text)-1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction et écouteur du bouton Annuler
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.btRetour.evenementClick = this.btRetour.on("click", onClicA);
function onClicA(evt) {
console.log("retour au menu");
clearTimeOut(this.leTimeOut);
evt.remove(); //retrait de l'écouteur (la méthode facile!)
this.parent.gotoAndStop("Intro");
}
Может вам введите свой код в вопрос как блок кода? С кодом с изображения очень сложно работать. – Matt
Вы должны предоставить код. В противном случае вы собираете downvotes – Mojtaba
там вы идете. должно быть лучше сейчас –