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

30 Second Countdown Timer

New Here ,
Dec 17, 2017 Dec 17, 2017

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.

Views

1.7K

Translate

Translate

Report

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);

Votes

Translate

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

Copy link to clipboard

Copied


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


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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Yup that's exactly it. Thanks a lot.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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