-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert.as
104 lines (89 loc) · 2.88 KB
/
Convert.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//****************************************************************************
// Author Scile
// Site www.scile.cn
// Version 1.0
// Fri Feb 02 15:55:15 2009
//****************************************************************************
// Language Version: ActionScript 3.0
// Runtime Versions: Flash Player 9
//****************************************************************************
package{
import flash.geom.Rectangle;
import flash.display.DisplayObject;
public class Convert{
public function Convert() {
throw new Error("You shouldn't use the new operator!");
}
// millisecond To second
public static function millisecondToSecond(ms:Number):Number{
var s = Math.floor(ms/1000);
return s;
}
// second To millisecond
public static function secondToMillisecond(s:Number):Number{
var ms = Math.floor(s*1000);
return ms;
}
// millisecond To time
public static function millisecondToTime(ms:Number):String{
var s = millisecondToSecond(ms)
var theSec = s%60;
var theMin = (s - theSec)/60;
if (theSec<10) {
theSec = "0" + theSec;
}
if (theMin<10) {
theMin = "0" + theMin;
}
var theTime = theMin + ":" + theSec;
return theTime;
}
// second To time
public static function secondToTime(s:Number):String{
var theSec = s%60;
var theMin = (s - theSec)/60;
if (theSec<10) {
theSec = "0" + theSec;
}
if (theMin<10) {
theMin = "0" + theMin;
}
var theTime = theMin + ":" + theSec;
return theTime;
}
//displayInBox
public static function displayInBox(displayObject:DisplayObject, rect:Rectangle):DisplayObject{
var dwh = displayObject.width/displayObject.height;
var rwh = rect.width/rect.height;
if(dwh > rwh){
displayObject.width = rect.width;
displayObject.height = rect.width / dwh;
}else{
displayObject.height = rect.height;
displayObject.width = rect.height * dwh;
}
displayObject.x = rect.x + (rect.width - displayObject.width)/2;
displayObject.y = rect.y + (rect.height - displayObject.height)/2;
return displayObject;
}
//formatColorHex24
public static function formatColorHex24(color:uint):String{
var r:String = ((color >> 16) & 0xFF).toString(16);
r = (r.length > 1) ? r : "0" + r;
var g:String = ((color >> 8) & 0xFF).toString(16);
g = (g.length > 1) ? g : "0" + g;
var b:String = (color & 0xFF).toString(16);
b = (b.length > 1) ? b : "0" + b;
return "0x" + r.toUpperCase() + g.toUpperCase() + b.toUpperCase();
}
public static function formatNum(num:uint):String {
var numStr:String = num.toString();
var len:int = numStr.length / 3;
var str:int = numStr.length % 3;
for(var i:int; i<len;i++){
numStr = numStr.substr(0,str+(4*i)) +","+ numStr.substr(str+(4*i))
}
return numStr;
}
}
}