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.4K

Likes

translate

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

Adobe Community Professional , Dec 17, 2017 Dec 17, 2017
"this" is undefined in countdown().  try:var timerId = setInterval(countdown.bind(this), 1000);

Likes

translate

Translate

Translate
Adobe Community Professional ,
Dec 17, 2017 Dec 17, 2017

Copy link to clipboard

Copied


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


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

Likes

translate

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.

Likes

translate

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
Adobe Community Professional ,
Dec 17, 2017 Dec 17, 2017

Copy link to clipboard

Copied

you're welcome.

Likes

translate

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

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

Likes

translate

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