现在使用的服务器连接类

      FCS 2005-9-7 11:18
dynamic class lu.com.FScon extends NetConnection {
    //初始化事件函数
    var addEventListener:Function;
    var removeEventListener:Function;
    var dispatchEvent:Function;
    var dispatchQueue:Function;
    // 标志定义
    var handleClose:Boolean = true;
    function FScon() {
        super();
        mx.events.EventDispatcher.initialize(this);
    }
    function connectionClosed(type, info) {
        if (handleClose) {
            dispatchEvent({target:this, type:type, info:info});
        }
        handleClose = false;
    }
    function onStatus(info) {
        var code = info.code.substring(info.code.indexOf(".")+1);
        switch (code) {
        case "Connect.Success" :
            dispatchEvent({target:this, type:"onConnect", info:info});
            break;
        case "Connect.Rejected" :
            connectionClosed("onReject", info);
            break;
        case "Connect.Closed" :
            connectionClosed("onClose", info);
            break;
        case "Connect.Failed" :
            connectionClosed("onFail", info);
            break;
        case "Connect.AppShutdown" :
            connectionClosed("onClose", info);
            break;
        case "Connect.InvalidApp" :
            connectionClosed("onReject", info);
            break;
        case "Call.Failed" :
            dispatchEvent({target:this, type:"onCall", info:info});
            break;
        }
    }
    function connect() {
        handleClose = true;
        return super.connect.apply(super, arguments);
    }
    function close() {
        handleClose = false;
        super.close();
    }
}
使用方法:
import lu.com.FScon;
var con_str:String = "rtmp:/app";
var con_nc = new FScon();
con_nc.connect(con_str);
with (con_nc) {
    addEventListener("onConnect", this);
    addEventListener("onReject", this);
    addEventListener("onClose", this);
    addEventListener("onFail", this);
}
function onConnect(info) {
    trace("success");
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}