Skip to main content
Participant
October 5, 2023
Question

Countdown timer using AS3 not showing up in dynamic text box

  • October 5, 2023
  • 4 replies
  • 242 views

Hello! I'm trying to make a countdown timer with AS3 in a dynamic text box to add to my timed puzzle game. The "100" simply won't show up in the text box. 

The code:

 

var nCount = 100;

timer_txt.text = nCount.toString();

 

I tried this exact same code in a new document, and it worked perfectly. However, in the file I'm editing, there's already a lot of extra (not DRY) code that I think is interferring with the timer.

I would copy paste my existing code but it's 1600+ lines and would clog up this post (happy to put the code up later if someone needed it). Any help would be appreciated!

 

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

kglad
Community Expert
Community Expert
October 5, 2023

is there an error message when testing?

 

if not, encode a trace statement that repeatedly polls your textfield's text.

Participant
October 5, 2023

There wasn't an error message, and the trace returned "100" so it seems to work that way...

 

I commented out my existing code and tried it again - I'm following a tutorial and tried this code

var nCount: Number = 100;

var myTimer: Timer = new Timer(1000, nCount);

 

timer_txt.text = nCount.toString():

myTimer.start();

 

myTimer.addEventListener(TimerEvent.TIMER, countdown);

 

function countdown(e: TimerEvent): void {

    nCount--;

    timer_txt.text = nCount.toString():

}

 

which returned error 1009. I tested this code in a seperate document and it worked perfectly. Not sure what's going on, I'm new to AS3.

Participant
October 5, 2023

Also, everything is on frame 1 so I don't understand why the function or variable (or something) can't be accessed