搜索

  • 好友链接

  • 链接表

  • Meta

    日志分类

    日志归档

    本月top点击

    历史top点击

    28

    [转贴]flash与后台数据交换方法整理2-Flash Remting篇

    二、Flash Remoting
    Flash Remoting这种数据接口是四个之中效率最高的!
    其优点:
    1.支持数据类型比较多(Converting from application server data types to ActionScript);
    2.传递数据量比较大;
    3.运行效率是现有几个当中最高的;
    4.对各种后台的支持也比较好;
    5.其还有调试模块(NetConnection Debugger)
    fr_debugger
    其缺点:
    1.需要flash端装Flash Remoting MX Components(这个是免费提供的);
    2.需要后台服务端装相应版本的Flash Remoting模块才可以使用,MM提供的模块有j2ee和.net两个版本是要收费的,好在网上还有两个开源的(OpenAMF,AMFPHP);
    3.好像Remoting对虚拟主机的支持不太好(可以去google搜索一下,有没有解决方法).

    1. ================================================================
    2.   Flash端代码说明:(我这里用as1.0版本为例,其他版本到MM站查找)
    3. ================================================================
    4.   //加载Remoting Component代码,这个是必须的;
    5.   #include "NetServices.as"
    6.   //加载Remoting 调试模块代码,这个是可选择的,用NetConnection Debugger查看调试信息;
    7.   #include "NetDebug.as"
    8.   if (inited == null){ 
    9.     inited = true;
    10.     //设置默认网关;
    11.     NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway");
    12.     //建立网关连接;
    13.     gateway_conn = NetServices.createGatewayConnection();
    14.     //获取一个服务;
    15.     myService = gateway_conn.getService("myservice", this);
    16.   }
    17.  
    18.   //定义调用方法的函数;
    19.   function getString(name){
    20.     //调用Remoting的getString方法;
    21.     myService.getString(name);
    22.   } 
    23.   //定义返回结果的函数;
    24.   function getString_Result(result){
    25.     //result就为返回的结果;
    26.     trace(result);
    27.   }
    28.   //定义返回状态的函数,此为可选的;
    29.   function getString_Status(error){ 
    30.     trace("getString_Status");
    31.     trace(error.code);
    32.     trace(error.description);
    33.     trace(error.details);
    34.   }
    35.  
    36.   //调用函数;
    37.   getString("kinglong");
    1. ================================================================
    2.   服务端方法定义(我这里以Coldfusion Component为例,其他版本请参考相应的资料)
    3. ================================================================
    4. <!---文件名为myservice.cfc--->
    5. <cfcomponent displayname="我的服务">
    6. <!---定义了getString方法,需将access设为remote,否则Flash remoting无法调用此方法--->
    7. <cffunction name="getString" access="remote" returntype="string">
    8.   <cfargument name="name" type="string" required="true">
    9.   <cfset myResult = arguments.name & ",欢迎你!">
    10.   <cfreturn myResult>
    11. </cffunction>
    12. </cfcomponent>

    另附上Flash Remoting的在线帮助文件(Flash Remoting LiveDocs),MM网站上的Remoting

    相关日志

    评论暂缺

    还没有任何评论。

    留下评论