# Frame-based counter problem

**URL:** https://forum.kirupa.com/t/frame-based-counter-problem/325372
**Category:** Uncategorized
**Created:** [October 12, 2011, 12:14am UTC](https://forum.kirupa.com/t/frame-based-counter-problem/325372 "2011-10-12T00:14:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![drpelz](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@drpelz](https://forum.kirupa.com/u/drpelz)
#### Post date: [October 12, 2011, 12:14am UTC](https://forum.kirupa.com/t/frame-based-counter-problem/325372/1 "2011-10-12T00:14:35Z")

</div>

Hello folks,

I have this frame-based counter I use instead of the timer-class because everything in my game is frame-based. This counter ensures that everything runs fine even when used on old computers.

I would like to know if it makes sense to create a tenth-second-frame-based-counter (or even a twentieth-second-frame-based counter). Basically it would be nearly the same counter like the one below except for the fact that the framesPerSecond-variable is divided by 10 or 20 and instead of using seconds I use tenthsesonds or twentiethseconds.

Is that a good or bad idea? Is there basically a difference between frame-based counters and timers when used on old computers?  
I’m not sure about this topic therefore I ask.

```auto

{
	import flash.events.*;
	
	
	public class BasicFrameTimer extends EventDispatcher
	{
		public static const TIME_IS_UP:String = "timesup";
		public var countUp:Boolean = false;
		public var min:int = 0;
		public var max:int;
		public var maxSet:Boolean = false;
		public var seconds:int;
		private var frameCount:int;
		public var started:Boolean = false;
		private var framesPerSecond:int;
		
		public function BasicFrameTimer(framesPerSecond:int) {
			this.framesPerSecond = framesPerSecond;
	
		}
		
		public function start():void {
			frameCount = 0;
			started = true;
		}
		
		public function stop():void {
			started = false;
		}
		
		public function reset():void {
			if (countUp) {
				seconds = 0;
			} else {
				seconds = max;
			}
		}
		
		public function update():void {
			
			if (started) {
				frameCount++;
				if (frameCount > (framesPerSecond)) {
					frameCount = 0;
					
					if (countUp) {
						seconds++;
						
						if (maxSet == true && seconds == max) {
							stop();
							dispatchEvent(new Event(TIME_IS_UP));
						}
					} else {
						seconds--;
						if (seconds == min) {
							stop();
							dispatchEvent(new Event(TIME_IS_UP));
						}
					}
				}
				
			}
			
			
		}
		
	}
}

```
