超級SWF跟蹤器-巧用LocalConnection的代碼_Flash As

來源:互聯網
上載者:User
FLASH中的trace只能在FLASH IDE中跟蹤看到,如果你將SWF發布到網上,是看不到trace的調試資訊,這給開發網路FLASH帶來的調試上的困難,那有沒有好的辦法來解決這個問題呢,不管SWF發布到什麼地方,開啟一個本地SWF跟蹤器來接收調試訊息那豈不是很好,因為我嘗試了各種方法,從SharedObject的本機物件到遠程對象到LocalConnection的方法都嘗試一遍(使用LocalConnection是從Breeze AddIn中發現的一個“秘密”,感覺SNOW給我了一個提示,發現了其中的“奧秘”),在需要調試的SWF中使用下面的類:
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,用來顯示跟蹤的訊息!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.