FORUMS: list search recent posts

How to reverse timecode in AS3?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Johan le Roux
How to reverse timecode in AS3?
on Nov 12, 2008 at 1:50:46 pm

Hi

I am using a function to return the timecode of a flv file i am playing back. The timecode is displayed in a txt field: timeRemain_txt.

The function I am using to return the timecode (based on ns dur):

function formatTime(t:int):String
{
// returns the minutes and seconds with leading zeros
// for example: 70 returns 01:10
var s:int = Math.round(t);
var m:int = 0;
if (s > 0)
{
while (s > 59)
{
m++;
s -= 60;
}
return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
}
else
{
return "00:00";
}
}

Question: How do I reverse the timecode? so the counter is showing the duration of the remaining time of the video rather than the elapsed time?

Thx


Return to posts index

Johan le Roux
Re: How to reverse timecode in AS3?
on Nov 13, 2008 at 10:58:52 am

I don't seem to be getting any responses in this forum :-(

Anyway with the help of a colleague we figured it out, here it is:

//timeElapsed in milliseconds
var timeElapsed:Number = nsStream.time;
//duration in milliseconds
var duration:Number = objInfo.duration;
var timeRemain:Number = duration - timeElapsed;
timeRemain_txt.text = "-" + formatTime(timeRemain);

//formatTime() takes the milliseconds and converts them to timecode


function formatTime(t:int):String
{
// returns the minutes and seconds with leading zeros
// for example: 70 returns 01:10
var s:int = Math.round(t);
var m:int = 0;
if (s > 0)
{
while (s > 59)
{
m++;
s -= 60;
}
return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
}
else
{
return "00:00";
}
}

// Works perfectly!! :-)




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]