# Timecode / Counter - AS3 Player

**URL:** https://forum.kirupa.com/t/timecode-counter-as3-player/284135
**Category:** flash
**Created:** [March 15, 2009, 8:09pm UTC](https://forum.kirupa.com/t/timecode-counter-as3-player/284135 "2009-03-15T20:09:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![losa03](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@losa03](https://forum.kirupa.com/u/losa03)
#### Post date: [March 15, 2009, 8:09pm UTC](https://forum.kirupa.com/t/timecode-counter-as3-player/284135/1 "2009-03-15T20:09:46Z")

</div>

HI, Need something like this for AS3 (my player not using netstream)

> **[FLVPlayback Display Timecode](https://www.kirupa.com/forum/showthread.php?t=253429)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

var listenerObject:Object = new Object();  
var \_root.fullDuration: null;  
listenerObject.metadataReceived = function(eventObject:Object):Void {  
\_root.fullDuration = \_root.prettyTime(flv\_playback.metadata.duration);  
};  
listenerObject.playheadUpdate = function(eventObject:Object):Void {  
var paTime = flv\_playback.playheadTime;  
if(\_root.fullDuration != null){  
//updates the text box with the instance name timeCode\_txt on the root timeline.  
//best to use a monospace typeface like calibri for the textbox font.  
\_root.timeCode\_txt.text = \_root.prettyTime(flv\_playback.playheadTime) + " / " + \_root.fullDuration;  
}  
};

flv\_playback.addEventListener(“metadataReceived”, listenerObject);  
flv\_playback.addEventListener(“playheadUpdate”, listenerObject);

function prettyTime(timeinSeconds):String{  
var seconds:Number = Math.floor(timeinSeconds);  
var minutes:Number = Math.floor(seconds / 60);  
var hours:Number = Math.floor(minutes / 60);

```
//Storing the remainder of this division problem
seconds %= 60;
minutes %= 60;
hours %= 24;

//Converting numerical values into strings so that
//we string all of these numbers together for the display
var sec:String = seconds.toString();
var min:String = minutes.toString();
var hrs:String = hours.toString();

//Setting up a few restrictions for when the current time reaches a single digit
if (sec.length &lt; 2) {
    sec = "0" + sec;
}

if (min.length &lt; 2) {
    min = "0" + min;
}

if (hrs.length &lt; 2) {
    hrs = "0" + hrs;
}

//Stringing all of the numbers together for the display
var time:String = hrs + ":" + min + ":" + sec;
//Setting the string to the display
return time;

```

}
