開發環境
Java Virtual Machines
l JDK 1.5 或更高
Application Servers
l Java Servlet container supporting servlet 2.3 或更高
Flex/AIR Applications using BlazeDS
l Flex SDK 3.2 build 3794 (3.0.2.2.14193)
l AIR 1.1 runtime
l Flash Player 9
下載BlazeDS
利用eclipse tomcat plugin建立Tomcat Project
將下載的BlazeDS裡 blazeds.war解開,複製其WEB-INF下所有檔案至Project裡建立Hello.java
package hello;
public class HelloWorld {
public String sayHelloTo(String str) {
System.out.println("Hello " + str);
return "Hello " + str;
}
public String test() {
return "HelloWorld";
}
}
在remote-config.xml增加
<destination id="helloworld"> <properties> <source>hello.HelloWorld</source> </properties> </destination>
建立好打開Tomcat測試,自行測試是否能運行
接下利用Flex Builder (至官方網站下載試用版) 來建立Flex Project
Application server type選擇J2EE
設定路徑,設定後好點選Validate Configuration是否連結成功
撰寫mxml內容
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent import mx.utils.ObjectUtil; import mx.controls.Alert; import mx.utils.StringUtil; private function resultHandler(event:ResultEvent):void { //used for debugging - shows details about result //returned by the Java class method Alert.show( ObjectUtil.toString(event.result) ); } private function faultHandler(event:FaultEvent):void { Alert.show( ObjectUtil.toString(event.fault) ); } ]]> </mx:Script> <mx:RemoteObject id="ro" destination="helloworld" source="hello.HelloWorld" result="resultHandler(event)" fault="faultHandler(event)"/> <mx:Button label="Get Hello World!" click="ro.test()"/> </mx:Application>
destination是在remote-config.xml所建立的
呼叫HelloWorld裡的test
直接執行Flex Project
設定沒問題的話畫面會自動導至
執行畫面





0 意見:
張貼留言