class fj.util.JTracer {
public static var debug:Boolean=true;
private static var _instance:JTracer;
private var _lc:LocalConnection;
private function JTracer(){
this._lc=new LocalConnection();
this._lc.allowDomain=function(domain:String):Boolean{
return true;
}
}
public static function trace(msg:Object):Void{
if(!JTracer.debug){
return;
}
if(JTracer._instance==undefined){
JTracer._instance=new JTracer();
}
JTracer._instance.traceMsg(msg);
}
private function traceMsg(msg:Object):Void{
trace(msg);
this._lc.send("localhost:trace","trace",this._lc.domain(),msg);
}
}
使用方法很简单,就是JTracer.trace("我来试试!");
SWF跟踪器中的代码如下:
import fj.util.JDelegate;
class view.JDebug {
private var _ui:MovieClip;
private var _lc:LocalConnection;
function JDebug(ui){
this._ui=ui;
this.init();
}
private function init(){
this._lc=new LocalConnection();
this._lc.allowDomain=function(domain):Boolean{
return true;
}
this._lc.connect("trace");
this._lc.trace=JDelegate.create(this,onTrace);
}
private function onTrace(domain:String,msg:Object){
this._ui.msg_ta.text+=domain+":"+msg+"\n";
}
}
这个需要放一个组件TextArea名字叫msg_ta,用来显示跟踪的消息!