Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

30 Second Countdown Timer

New Here ,
Dec 17, 2017 Dec 17, 2017

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.

1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 17, 2017 Dec 17, 2017


"this" is undefined in countdown().  try:


var timerId = setInterval(countdown.bind(this), 1000);

Translate
Community Expert ,
Dec 17, 2017 Dec 17, 2017


"this" is undefined in countdown().  try:


var timerId = setInterval(countdown.bind(this), 1000);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2017 Dec 17, 2017

Yup that's exactly it. Thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2017 Dec 17, 2017

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2021 Apr 08, 2021
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines