flex與java交互

[b]Eclipse中flex插件的安裝[/b]
方法1:直接下載Flex Builder Eclipse 插件版安裝
方法2:安裝Flex Builder 3,然後將安裝目錄下features和plusins目錄中的內容copy到eclipse的對應目錄中

[b]Flex和java交互[/b]
1.新建一個flex項目
[img]http://dl.iteye.com/upload/picture/pic/62145/c45d2a9b-89da-3a26-925c-98a9afa72133.png[/img]
[img]http://dl.iteye.com/upload/picture/pic/62143/8a62a568-5c38-34a9-8555-6a3aa7605bc6.png[/img]
Blazeds.war放在tomcat的webapps目錄下,爲flex和java的交互提供支持。

2.和java整合
[img]http://dl.iteye.com/upload/picture/pic/62141/b8b24f30-4944-368b-a37d-a80a515c1c7e.png[/img]
選擇Add Web Project Capabilities
[img]http://dl.iteye.com/upload/picture/pic/62139/b4edf166-a4ce-3ff6-a3af-3f1019a1f273.png[/img]

3.修改配置
[img]http://dl.iteye.com/upload/picture/pic/62137/fa62b703-9fd9-3d86-8331-a9a3010fd074.png[/img]
把Context root改爲項目名稱

4.HelloWorld
目錄結構:
[img]http://dl.iteye.com/upload/picture/pic/62147/2e7b4b8a-786b-34ab-8b35-c6303d9eeace.png[/img]

源碼:
myflex.mxml

<?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.ResultEvent;
import mx.controls.Alert;
[Bindable]
function sendRequest(){
hw.printHelloWorld();
hw.addEventListener(ResultEvent.RESULT,showResult);
}

function showResult(event:ResultEvent){
lab.text=event.result as String;
}

]]>
</mx:Script>
<mx:RemoteObject id="hw" destination="HelloWorld" fault="Alert.show(event.fault.toString())">

</mx:RemoteObject>
<mx:Panel x="340" y="77" width="284" height="242" layout="absolute" >
<mx:VBox>
<mx:Button label="HelloWorld" fontSize="15" click="sendRequest()"></mx:Button>
<mx:Label id="lab"></mx:Label>
</mx:VBox>
</mx:Panel>
</mx:Application>


HelloWorld.java

package bean;

public class HelloWorld{
public String printHelloWorld(){
String str = "Hello World!";
return str;
}
}


remoting-config.xml

<destination id="HelloWorld">
<properties>
<source>bean.HelloWorld</source>
<scope>application</scope>
</properties>
</destination>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章