flex RemoteObject 通信
1:flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
//引如需要的类库
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.RemoteObject;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
//声明一个RemoteObject
// private var HelloJava:RemoteObject=new RemoteObject("TestLcds1");
private function JavaHello():void{
//添加调用成功和调用失败的监听
Hellojava.addEventListener(FaultEvent.FAULT,HelloJavaFault);
Hellojava.addEventListener(ResultEvent.RESULT,HelloJavaResult);
Hellojava.HelloLCDSRemoting(name_txt.text);
}
//声明调用失败的监听函数
private function HelloJavaFault(event:FaultEvent):void{
//显示错误信息
Alert.show(event.message.toString(),"调用失败");
}
//声明调用成功的监听函数
private function HelloJavaResult(event:ResultEvent):void{
//显示返回结果
Alert.show(String(event.result),"调用成功");
}
]]>
</mx:Script>
<mx:Style>
global{
fontSize:12pt;
}
</mx:Style>
<mx:RemoteObject id="Hellojava"destination="ctiStatusReasonDetailService" source="package1.Class1">
</mx:RemoteObject>
<mx:Button label="调用Java类" horizontalCenter="0" verticalCenter="22" click="JavaHello()"/>
<mx:TextInput id="name_txt" horizontalCenter="0" verticalCenter="-23" />
</mx:Application>
2:服务器里面配置:
在remoting.config.xml中加入
<destination id="ctiStatusReasonDetailService">
<properties>
<factory>spring</factory>
<source>TestLcds2</source>
</properties>
destination:String (默认为 null) —RemoteObject 的destination属性必须匹配 services-config.xml 中的destination的ID属性值。