Thanks for taking the time ATNO/TW to write that code. After some trial and error myself this morning and searching through the help docs I did find a shorter way to do it there is still some issues I will discuss in a min but here is the code I did to achieve my counter backwards. It is a much shorter way to do it.
this.addEventListener(Event.ENTER_FRAME, updateNP);
function updateNP(event:Event):void {
var totalSeconds:Number = flvControl.playheadTime; // current time on playhead
var totalSeconds2:Number = flvControl.totalTime; // total time in miliseconds
var timeLeft:Number = totalSeconds2 - totalSeconds;
var minutes:Number = Math.floor(timeLeft / 60);
var seconds:Number = Math.floor(timeLeft % 60);
var min:String = minutes.toString();
var sec:String = seconds.toString();
if(minutes < 10){
min = "0" + min;
}
if(seconds < 10){
sec = "0" + sec;
}
//trace(min+":"+sec);
timeBox_txt.text = min + ":" + sec;
}
- this.addEventListener(Event.ENTER_FRAME, updateNP);
- function updateNP(event:Event):void {
- var totalSeconds:Number = flvControl.playheadTime; // current time on playhead
- var totalSeconds2:Number = flvControl.totalTime; // total time in miliseconds
-
- var timeLeft:Number = totalSeconds2 - totalSeconds;
- var minutes:Number = Math.floor(timeLeft / 60);
- var seconds:Number = Math.floor(timeLeft % 60);
- var min:String = minutes.toString();
- var sec:String = seconds.toString();
-
- if(minutes < 10){
- min = "0" + min;
- }
- if(seconds < 10){
- sec = "0" + sec;
- }
-
- //trace(min+":"+sec);
- timeBox_txt.text = min + ":" + sec;
- }
Basically what I did is take the playheadTime which would be the current time in the flv file and subtracted it from the totalTime which gave me the time in milliseconds.
Then I did some conversions using the Math.floor to get them into manageable numbers.
Now this next part is how I dealt with the - numbers and adding leading 0's. It took me a bit cause the coding is different in AS3 then what it was in AS2, which is IMO not a very good move by adobe to not make AS3 very backward compatible with AS2 script but that is another topic.
But what I did was convert my numbers to string to display in the Game clock checking if the value while it still a number is less then 10 and if so then add a 0 to the string. then from there display it in the dynamic text field.
The only issue I really have to deal with is when the file begins to play for quick flash in the game clock you see the NaN for not a number flash before it changes to the time. So I'm currently trying to figure out how to get a preloader to work hoping that fixes it if not I can probably add another if statement to say something if the value is NaN display 1:50 then it will change once the script gets going.
But like you this might not be the most professional way, like I said it just took some fiddling with my variables and converting them to string and what not to get it to work but it is a much condensed version of what you did. But none the less at the very lest we found two ways for others to look at and build off of.
Again thanks for the time you spent playing around with my code.