本人在实现此功能的过程中,费了不少劲,才实现。以下内容有些摘自网上,在这里只是把自己遇到的问题记录下来,以便以后查阅。
一:首先安装好myeclipse6.5,设置好jdk环境。
二:安装flexbuilder的eclipse插件版,安装过程中注意选择myeclipse的路径。要选择myeclipse6.5下的eclipse文件夹。
三:在安装好的flexbuilder目录中找到sdks文件夹,将其复制到myeclipse6.5目录下的eclipse文件夹中,然后配置插件(或者把flexbuilder下中eclipse下的features和plugins分别复制到myeclipse6.5目录下的eclipse文件夹下对应的文件夹中或者采用其他配置插件的方法,我建议采用建立link文件夹,建立link文件的方法)
四:当一切环境准备好后,就开始了flex与java通信。具体过程如下
http://blog.csdn.net/roc230/archive/2010/06/07/5652746.aspx
这是一位csdn朋友的博客,里面介绍的很详细,这里不做更详细的介绍。只是这里自己用的是blazed,不是lcd
blazed:blazeds-turnkey-3.2.0.3978 下载地址是:http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978 /blazeds-turnkey-3.2.0.3978.zip(一般解压后找到blazed文件,将其放到tomcat安装目录下的webapps文件夹下即可。具体的可以参考网上更多的信息)
五:相应的工程建好后,就可以进行相应的程序编写
首先建立java类
package com.oraro.flex;
public class Flex {
public String sayString(String str){
System.out.println("click here!");
return "hello" + str;
}
}
然后修改相应的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.controls.Alert;
import mx.rpc.events.ResultEvent ;
[Bindable]
private var helloResult:String ;
private function sayHelloTo(): void {
Alert.show(inputText.text);
ro.sayString(inputText.text);
}
private function resultHandler ( event:ResultEvent ): void {
helloResult = event.result as String ;
}
]]>
</mx:Script>
<mx:RemoteObject id ="ro" destination = "flex" result = "resultHandler(event)" />
<mx:HBox width = "100%">
<mx:TextInput id = "inputText"/>
<mx:Button label = "Submit" click = "sayHelloTo()"/>
</mx:HBox >
<mx:Label text = "{helloResult}"/>
</mx:Application>
接着在remoting-config.xml文件中添加
<destination id="flex">
<properties>
<source>com.oraro.flex.Flex</source>
</properties>
</destination>
以下内容
以上工作做完后,就完成了flex与java的通信。当然通信方式是通过RemoteObject实现的。
六:最后有一点需要注意的
就是要把你的Flex Server下的Context root配置 ,改成和你项目同名。
否则会报错误,如:
'http://localhost:8080/WebRoot/messagebroker/amf'路径不对
编译的时候出现faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebRoot/messagebroker/amf''这样的错误。
当然,也可以分别建立flex和javaweb工程,然后再做相应的配置,在这里就不具体的叙述了。