The following code is working fine........you can try this one ,but remember the time should be in seconds.
package common
{
import mx.controls.ComboBox;
public class Utils
{
public static var timeInPixel:Number = 60 * 0.033;//60 * 0.033;//
public static var pixelInTime = 60/30;
public static var inversePixelInTime = 30/60;//3/60;
public function Utils()
{
}
public static function toTimeString(seconds:uint)
{
var secs:int = seconds%60;
var mins:int = seconds/60;
var hrs:int = 0;
if(mins > 60)
{
hrs = mins/60;
mins = mins%60;
//return hrs+':'+mins+':'+secs;
}
return ((hrs>0)?(hrs+':'):(''))+((mins<10)?('0'+mins):(mins))+':'+((secs<10)?('0'+secs):(secs));
}
public static function getPixelForTime(time, unit= 'second'){
var pixel = time * pixelInTime; //( 60 total time 3sec time per pixel)
return pixel;
}
public static function getTimeForPixel(pixel, unit = 'second'){
var time = pixel * timeInPixel;
if(unit == 'minute'){
time = time / 60;
}
return time;
}
public static function positionText(seconds:Number):String
{
var min:Number = Math.floor(seconds / 60);
var sec:Number = Math.floor(seconds % 60);
if(sec < 0) sec = 0;
if(min <0) min = 0;
if (isNaN(min) || isNaN(sec))
{
return "";
}
return min + ":" + (sec < 10 ? "0" + sec:sec);
}
public static function presetComboBox(combo:ComboBox,presetValue=""){
for(var i= 0 ; i < combo.dataProvider.length; i++){
if(combo.dataProvider[i].data == presetValue){
combo.selectedIndex = i;
}
}
}
}
}
With regards,
Er.Animesh Nanda
Web Developer,
Manusis Technology,Bengaluru,Karnataka.
No comments:
Post a Comment