使用Flash Remoting

以Flash Remoting for J2EE为例,分为两部分:J2EE部分与Flash部分。
Flash Remoting for Java自带的文档《flashRemoting.pdf》很详细。
之所以写这篇笔记有两个原因:
1 该文档可能有点过时,比如导入外部类的代码无法工作。
2 介绍OpenAMF的使用及对其Spring的支持。

1 J2EE部分
J2EE应用通过Flash Remoting Gateway暴露服务(可以是Java对象,Servlet,EJB等 )。
Adobe提供了一个商业产品,开源产品可以选择OpenAMF。
web.xml配置分别如下:
Adobe Flash Remoting for J2EE

<servlet>
    <servlet-name>FlashGatewayServlet</servlet-name>
    <servlet-class>
        flashgateway.controller.GatewayServlet
    </servlet-class>
</servlet>
 

OpenAMF

<servlet>
    <servlet-name>DefaultGateway</servlet-name>
    <servlet-class>org.openamf.DefaultGateway</servlet-class>
    <init-param>
        <param-name>OPENAMF_CONFIG</param-name>
        <param-value>/WEB-INF/openamf-config.xml</param-value>
    </init-param>
</servlet>

OpenAMF配置文件openamf-config.xml
与spring结合:配置invoker

<invoker>
    <name>Spring</name>
    <class>org.openamf.invoker.SpringBeanInvoker</class>
</invoker>
这样就可以暴露spring配置的bean


2 Flash部分
又可分为client-side和server-side。Flash 8与FMS 2使用的脚本版本不同,因此具体编程存在差别。
2.1 client-side
如果使用Flash 8开发,需要需要安装相应的flash remoting component。
下载地址是:http://www.adobe.com/products/flashremoting/downloads/components/
示例代码:

 

import mx.remoting.NetServices;
import mx.remoting.Service;

System.security.allowDomain("*");
var gateway:String = "flash_remoting_gateway_url"; // modify this

NetServices.setDefaultGatewayUrl(gateway);
var gatewayConnection:NetConnection = NetServices.createGatewayConnection();
var service:Service = gatewayConnection.getService("SampleBean");

var sampleMethod_Result:Object = new Object();
sampleMethod_Result.onResult = function(result) {
	trace("result: " + result);
}
service.sampleMethod(sampleMethod_Result, "param1");
关于传递对象参数的问题参见文档。


2.2 server-side
FMS 2内置了对Flash Remoting的支持。
示例代码:

 

load("netservices.asc"); // use flash remoting

gateway = "flash_remoting_gateway_url"; // modify this

NetServices.setDefaultGatewayUrl(gateway);
gatewayConnection = NetServices.createGatewayConnection();
service = gatewayConnection.getService("SampleBean");

var sampleMethod_Result = new Object();
sampleMethod_Result.onResult = function(result) {
	trace("---------" + result);
}
service.sampleMethod(sampleMethod_Result, "param1");
 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值