本人在實現此功能的過程中,費了不少勁,才實現。以下內容有些摘自網上,在這裡只是把自己遇到的問題記錄下來,以便以後查閱。
一:首先安裝好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工程,然後再做相應的配置,在這裡就不具體的敘述了。