Search code examples
actionscript-3flashtimeractionscript

Actionscript 3.0 Timer doesn't display in text box


I am pretty new to actionscript and for one of my college finals I need to make a game. I'm almost finished but one of the most important things I need is a simple timer to just count up by 1 from 0 continuously. The timer works in my output but does not display in the textbox. Here's a picture.

https://i.sstatic.net/7dFAE.png

Edit: The white box in the picture is just a white rectangle, the textbox is over top of it

Code:

var upCounter:int = 0
var myTimer:Timer = new Timer(1000,0);

myTimer.addEventListener("timer", timerHandler)
myTimer.start();
myTimer:String;

function timerHandler(event:TimerEvent):void
{       
    trace(upCounter);       
    upCounter++;

}

Solution

  • You should update your dynamic text field inside the timerHandler like this :

    function timerHandler(event:TimerEvent):void
    {       
        trace(upCounter);       
        upCounter++;
    
        text_field.text = (upCounter).toString();
    
    }
    

    Also, you have to remove this line : myTimer:String; because it is useless.