Utility.as
1.2 KB
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
package
{
import flash.external.ExternalInterface;
import flash.utils.setTimeout;
/**
* the utility functions.
*/
public class Utility
{
/**
* total log.
*/
public static var logData:String = "";
/**
* whether string s endswith f.
*/
public static function stringEndswith(s:String, f:String):Boolean {
return s && f && s.indexOf(f) == s.length - f.length;
}
/**
* whether string s startswith f.
*/
public static function stringStartswith(s:String, f:String):Boolean {
return s && f && s.indexOf(f) == 0;
}
/**
* write log to trace and console.log.
* @param msg the log message.
*/
public static function log(js_id:String, msg:String):void {
if (js_id) {
msg = "[" + new Date() +"][srs-player][" + js_id + "] " + msg;
}
logData += msg + "\n";
trace(msg);
if (!flash.external.ExternalInterface.available) {
flash.utils.setTimeout(log, 300, null, msg);
return;
}
ExternalInterface.call("console.log", msg);
}
}
}