这个demo也是根据程序从前台页面执行到后台java程序的流程来书写的
注:在此程序中引入了blazeds
1. 页面中的组件元素
view plaincopy to clipboardprint
2. 实现click属性中的方法clickMe()函数
view plaincopy to clipboardprint
private function clickMe():void{
var value:String = this.username.text;
this.testService.sayHello(value);
}
]]>
private function clickMe():void{
var value:String = this.username.text;
this.testService.sayHello(value);
}
]]>
注意:在clickMe()函数中用到了远程对象testService,以及远程对象中的方法sayHello(),在书写该方法时并不会给出提示。
3. 在页面中引入远程对象testService
view plaincopy to clipboardprint
2)
3)
4. 介绍处理返回结果的处理函数returnResultHandler(event)
view plaincopy to clipboardprint
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function returnResultHandler(event:ResultEvent):void{
var str:String = String(event.result);
Alert.show(str);
}
]]>
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function returnResultHandler(event:ResultEvent):void{
var str:String = String(event.result);
Alert.show(str);
}
]]>
解释:1)event.result得到远程对象的结果返回值,并转换成String类型,并复制给str
2)弹出对话框并输出str变量的值 Alert.show(str);
5. remoting-config.xml文件里暴漏出java对象供flex页面使用
view plaincopy to clipboardprint
注意:在书写该文件的过程中并没有提示功能,大家输入的时候,请多注意!最好是copy
6.对应该配置文件中的远程对象com.test.service.TestService 类的文件如下:
view plaincopy to clipboardprint public class TestService {
public String sayHello(String name){
System.out.println("method=sayHello");
return "hello:"+name;
}
}
public class TestService {
public String sayHello(String name){
System.out.println("method=sayHello");
return "hello:"+name;
}
}
以上就是一个flex+java交互的小例子,该交互是通过Remote Object方法来完成!
作者“liuwang8888”