Copy link to clipboard
Copied
Hi, I am trying to create a countdown that counts down from 30 seconds for my game.
This is my code:
var secondsLeft = 30;
this.countdown_txt.text = secondsLeft;
var timerId = setInterval(countdown, 1000);
function countdown(){
if(secondsLeft == 0){
//doStuff
}
else{
secondsLeft--;
this.countdown_txt.text = secondsLeft;
}
}
When I run this I get an error that occurs on line 11: Uncaught TypeError: Cannot set property 'text' of undefined.
I'm not sure why this is the case as I have a similar setup for counting the score when clicking on a movieclip and that works fine. Any help would be appreciated.
"this" is undefined in countdown(). try:
var timerId = setInterval(countdown.bind(this), 1000);
Copy link to clipboard
Copied
"this" is undefined in countdown(). try:
var timerId = setInterval(countdown.bind(this), 1000);
Copy link to clipboard
Copied
Yup that's exactly it. Thanks a lot.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hi,
I have made a clock on a pdf file
But I want to insert a countdown of 120" in a pdf document (not in a HLML File)
I think I 'll have a text field with the result .... with which properties?
an action button start field with which properties ?
a action button reset with which properties ?
Can you help me please?
Thank you by advance
Henri