Flash 与FMS客户端互访
发布-liushuchao | 查看- | 发表时间-2009-10-11
程序代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute">
<mx:Script>
<![CDATA[
import test.NCClient;
private var nc:NetConnection;
private var ncClient:Object;
private var responder:Responder;
private function init():void{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
nc.connect("rtmp://127.0.0.1/share");
responder = new Responder(successHandler,failHandler);
}
private function netStatusHandler(e:NetStatusEvent):void{
if(e.info.code == "NetConnection.Connect.Success"){
callFMS.enabled = true;
nc.client = new NCClient();
}
}
private function successHandler(val:Object):void{
trace(val);
}
private function failHandler(val:Object):void{
trace(val);
}
private function callFMSHandler():void{
nc.call("test",responder,"sloppy");
}
]]>
</mx:Script>
<mx:Button id="callFMS" label="callFMS" enabled="false" click="callFMSHandler()" x="193" y="128">
</mx:Button>
</mx:Application>
Flex 客户端类文件:
程序代码package test
{
public class NCClient
{
public function NCClient()
{
}
public function callFlex():String{
return "yue";
}
}
}
FMS服务端代码:
程序代码Client.prototype.test = function( o ){
this.call("callFlex",new readHandler());
return o+"s";
}
application.onAppStart = function ()
{
trace("application start") ;
}
application.onAppStop = function ()
{
application.registerClass( "UserVO", null ) ;
trace("application stop") ;
}
readHandler = function(){
this.onResult = function(res){
trace("s"+res);
}
this.onStatus = function(info){
trace("Failed with code:" + info.code);
}
}
application.onConnect = function ( client )
{
trace("connect client : " + client) ;
application.acceptConnection( client ) ;
}
application.onDisconnect = function( client )
{
trace("disconnect client : " + client) ;
}
或许你还对下面的文章感兴趣

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。