2016-03-19 02:06:08 +00:00
|
|
|
package
|
|
|
|
{
|
|
|
|
import flash.external.ExternalInterface;
|
|
|
|
import flash.utils.setTimeout;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the utility functions.
|
|
|
|
*/
|
|
|
|
public class Utility
|
|
|
|
{
|
2016-03-19 02:18:11 +00:00
|
|
|
/**
|
|
|
|
* total log.
|
|
|
|
*/
|
|
|
|
public static var logData:String = "";
|
|
|
|
|
2016-03-19 02:06:08 +00:00
|
|
|
/**
|
2016-03-19 03:08:25 +00:00
|
|
|
* whether string s endswith f.
|
2016-03-19 02:06:08 +00:00
|
|
|
*/
|
|
|
|
public static function stringEndswith(s:String, f:String):Boolean {
|
|
|
|
return s && f && s.indexOf(f) == s.length - f.length;
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:08:25 +00:00
|
|
|
/**
|
|
|
|
* whether string s startswith f.
|
|
|
|
*/
|
|
|
|
public static function stringStartswith(s:String, f:String):Boolean {
|
|
|
|
return s && f && s.indexOf(f) == 0;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:06:08 +00:00
|
|
|
/**
|
|
|
|
* write log to trace and console.log.
|
|
|
|
* @param msg the log message.
|
|
|
|
*/
|
|
|
|
public static function log(js_id:String, msg:String):void {
|
2016-03-19 13:54:46 +00:00
|
|
|
if (js_id) {
|
|
|
|
msg = "[" + new Date() +"][srs-player][" + js_id + "] " + msg;
|
|
|
|
}
|
2016-03-19 02:06:08 +00:00
|
|
|
|
2016-03-19 02:18:11 +00:00
|
|
|
logData += msg + "\n";
|
|
|
|
|
2016-03-19 02:06:08 +00:00
|
|
|
trace(msg);
|
|
|
|
|
|
|
|
if (!flash.external.ExternalInterface.available) {
|
2016-03-19 13:54:46 +00:00
|
|
|
flash.utils.setTimeout(log, 300, null, msg);
|
2016-03-19 02:06:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalInterface.call("console.log", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|