# Need help creating a simple timer/counter

**URL:** <https://forum.kirupa.com/t/need-help-creating-a-simple-timer-counter/351928>\
**Category:** flash\
**Created:** [October 14, 2014, 6:25am UTC](https://forum.kirupa.com/t/need-help-creating-a-simple-timer-counter/351928 "2014-10-14T06:25:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![o111](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/o111/32/2123_2.png) [@o111](https://forum.kirupa.com/u/o111)\
**Post date:** [October 14, 2014, 6:25am UTC](https://forum.kirupa.com/t/need-help-creating-a-simple-timer-counter/351928/1 "2014-10-14T06:25:10Z")

</div>

[COLOR=#000000][FONT=verdana]Hi 🅱

[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]I am currently making a simple timer/counter in Flash and have run into a little problem. I have a very simple set-up: 1 frame and two dynamic text-boxes. Also two layers (one for the AS and one for the text-boxes).[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]I want the text-boxes to start out with their own number and count up from there. I’ve got the counting right, but right now they both start at zero. I want text-box 1 to start at “4 500 000” and text-box 2 to start at “2 600 000 000” and go from there.

[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]I am attaching the .fla - any help appreciated!

[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]Flash file: [http://www.filedropper.com/counterfla[/FONT][/COLOR]](http://www.filedropper.com/counterfla%5B/FONT%5D%5B/COLOR%5D)

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [October 14, 2014, 7:00am UTC](https://forum.kirupa.com/t/need-help-creating-a-simple-timer-counter/351928/2 "2014-10-14T07:00:47Z")

</div>

This should do the trick:

```auto
//Day-counter

day_txt.text = "4 500 000";
const dayStart:uint = 4500000
var daycounter:Timer = new Timer(100,0);

daycounter.addEventListener(TimerEvent.TIMER, dayCounter);

function dayCounter(event:TimerEvent):void {
	day_txt.text = (daycounter.currentCount + dayStart).toString().public::['toSpaceyFormat']()
}

String.prototype.toSpaceyFormat = function():String {
	return this.split('').reverse().map(function(e, i, a):* { return i % 3 ? e : e + ' ' }).reverse().join('')
}

daycounter.start();

//Year-counter;

year_txt.text = "2 600 000 000";
const yearStart:uint = 2600000000;

var yearcounter:Timer = new Timer(1,0);

yearcounter.addEventListener(TimerEvent.TIMER, yearCounter);

function yearCounter(event:TimerEvent):void {
	year_txt.text = (yearcounter.currentCount + yearStart).toString().public::['toSpaceyFormat']()
}

yearcounter.start();

```

---

<div class="post-metadata">

**Author:** ![o111](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/o111/32/2123_2.png) [@o111](https://forum.kirupa.com/u/o111)\
**Post date:** [October 14, 2014, 7:23am UTC](https://forum.kirupa.com/t/need-help-creating-a-simple-timer-counter/351928/3 "2014-10-14T07:23:55Z")

</div>

Thank you so much, Krilnon! I was in a bit of a deadline-squeeze here!
