PDA

View Full Version : create counter in text box...


BG Design
07-30-2010, 11:21 PM
'm trying to create a "counter" element that uses a formatted dynamic text box to count up in .1 increments, starting from a specified value.

Here's the code so far:

var counter:Number;
counter = 3.0

counterText.text=(String(counter));

var timer:Timer = new Timer(300);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(event:TimerEvent):void
{
???
}


What I can't figure out is what should go in the function area, to add .1 seconds each time the timer cycles.

BG Design
07-30-2010, 11:23 PM
"counterText" is, of course, the instance name of the dynamic text field.

rakosmanjr
07-31-2010, 03:51 AM
do

function onTimer(event:TimerEvent):void
{
counter += .1;
counterText.text = String (counter);
}

snickelfritz
07-31-2010, 04:31 AM
Technically, you probably should not cast a Number as a String.
Instead, convert the Number to a String:
counter.toString();