This is the source code for a simple chess timer (two players with alternating times) written in ActionScript 3.0 on the FlexBuilder platform.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import flash.events.*;
import mx.controls.*;
[Bindable]
public var time1:String = "00:00";
[Bindable]
public var time2:String = "00:00";
public var time1Front:int = 0;
public var time1Rear:int = 0;
public var time2Front:int = 0;
public var time2Rear:int = 0;
public var mainTimer:Timer = new Timer(1000);
public var turn:Boolean = false;
public var change:Boolean = false;
private function startF():void
{
if (!change)
{
mainTimer.start();
mainTimer.addEventListener(TimerEvent.TIMER,timeChange);
start.label = "Switch";
change = true;
}
else
{
turn = !turn;
}
}
private function timeChange(e:TimerEvent):void
{
if (turn)
{
this.player1.setStyle("backgroundColor",0x00FF00);
this.player2.setStyle("backgroundColor",0xFFFFFF);
time1Rear++;
if (time1Rear > 59)
{
time1Front++;
}
if (time1Front < 10)
{
time1 = "0" + time1Front.toString() + ":" + time1Rear.toString();
}
if (time1Rear < 10)
{
time1 = time1Front.toString() + ":0" + time1Rear.toString();
}
if (time1Front < 10 && time1Rear < 10)
{
time1 = "0" + time1Front.toString() + ":0" + time1Rear.toString();
}
if (time1Front > 10 && time1Rear > 10)
{
time1 = time1Front.toString() + ":" + time1Rear.toString();
}
}
else if (!turn)
{
this.player2.setStyle("backgroundColor",0x00FF00);
this.player1.setStyle("backgroundColor",0xFFFFFF);
time2Rear++;
if (time2Rear > 59)
{
time2Front++;
}
if (time2Front < 10)
{
time2 = "0" + time2Front.toString() + ":" + time2Rear.toString();
}
if (time2Rear < 10)
{
time2 = time2Front.toString() + ":0" + time2Rear.toString();
}
if (time2Front < 10 && time2Rear < 10)
{
time2 = "0" + time2Front.toString() + ":0" + time2Rear.toString();
}
if (time2Front > 10 && time2Rear > 10)
{
time2 = time2Front.toString() + ":" + time2Rear.toString();
}
}
}
private function resetF():void
{
start.label = "Start";
mainTimer.stop();
change = false;
this.player1.setStyle("backgroundColor",0xFFFFFF);
this.player2.setStyle("backgroundColor",0xFFFFFF);
time1 = "00:00";
time2 = "00:00";
time1Front = 0;
time1Rear = 0;
time2Front = 0;
time2Rear = 0;
}
]]>
</mx:Script>
<mx:Button x="444" y="246" label="Start" click="startF();" id="start"/>
<mx:Button x="583" y="246" label="Reset" click="resetF();" id="reset"/>
<mx:Canvas x="199" y="37" width="300" height="170" id="player1" backgroundColor="#FFFFFF">
<mx:Text x="106" y="10" text="Player 1" fontSize="20"/>
<mx:Label x="85.5" y="49" text="{time1}" width="130" height="50" fontSize="20" textAlign="center"/>
</mx:Canvas>
<mx:Canvas x="583" y="37" width="300" height="170" id="player2" backgroundColor="#FFFFFF">
<mx:Text x="106" y="10" text="Player 2" fontSize="20"/>
<mx:Label x="85" y="49" text="{time2}" fontSize="20" textAlign="center" width="130" height="50"/>
</mx:Canvas>
<mx:Text x="380" y="336" text="Made and designed by Matthew McNally in ActionScript 3.0" width="330"/>
</mx:Application>
Live demo:
http://checkgamertag.com/chess/