Posted By

vamapaull on 12/17/11


Tagged

time actionscript utility convert minutes seconds 3 timecode


Versions (?)

Timecode Utility


 / Published in: ActionScript 3
 

URL: http://blog.vamapaull.com/timecode-utility/

It's very useful if you build a FLV player for example, and want to convert the time into minutes:seconds (example: 6:13)

//apply it to your project like this (and don't forget to import the class): time.text = TimeUtil.getTimecode(timeValue);

  1. package com.vamapaull.utils
  2. {
  3. public class TimeUtil
  4. {
  5. public static function getTimecode(value:Number):String
  6. {
  7. var t:Number = Math.round(value),
  8. min:Number = Math.floor(t/60),
  9. sec:Number = t%60,
  10. tc:String = "";
  11.  
  12. if(min < 10)
  13. tc += "0";
  14.  
  15. if(min >= 1)
  16. {
  17. if (isNaN(min) == true) tc += "0";
  18. else tc += min.toString();
  19. }
  20. else
  21. tc += "0";
  22.  
  23. tc += ":";
  24.  
  25. if(sec < 10)
  26. {
  27. tc += "0";
  28.  
  29. if (isNaN(sec) == true) tc += "0";
  30. else tc += sec.toString();
  31. }
  32. else
  33. {
  34. if (isNaN(sec) == true) tc += "0";
  35. else tc += sec.toString();
  36. }
  37.  
  38. return tc;
  39. }
  40. }
  41. }

Report this snippet  

You need to login to post a comment.