天天看點

fms系列2 與fms伺服器互動

http://www.cnblogs.com/beniao/category/190537.html

import flash.net.NetConnection;

import flash.events.NetStatusEvent;

import flash.net.Responder;

var nc:NetConnection = new NetConnection();

var rp:Responder = new Responder(onSuccess,onFail);

nc.connect("rtmp://localhost/firstFmsApp");

nc.call("sayHelloWorld",rp,"World");

nc.client = this ;

nc.addEventListener(NetStatusEvent.NET_STATUS,onStatus);

function onStatus(e:NetStatusEvent):void{

    trace(e.info.code);

}

function onSuccess(e:Object):void{

    trace("Success:" +e.toString());

}

function onFail(e:Object):void{

    trace("Fail:"+ e.description());

}

===============================

在application下的檔案夾(程式)中履歷main.asc檔案(用來互動?),内容:

application.onConnect = function(client)

{

    client.sayHelloWorld = function (str)

{

    return "I can say hello :" + str ;

}

     this.acceptConnection(client);

}

======================================

client.後頭的應該是函數,str是參數,與上面定義的call函數中的第一個和第三個參數一緻;第二個參數是responder對象,responder對象有兩個參數,均是函數,分别是成功連接配接和連接配接失敗時調用。

nc,添加函數偵聽器 NetStatusEvent.NET_STATUS,顯示連接配接的情況。

====================================

結果輸出:

NetConnection.Connect.Success

Success:I can say hello :World

FMS