环境:eclipse 3.5 + tomcat 6.0 + flex builder 3.0 + blazeds-turnkey-3.2.0.3978.zip(adobe网站上下载)
(因为不能放截图所以只能叙述了)
1,新建一个 java web 项目 例名为 :testjava;
2,在此工程中写一个简单的类:
package cn.com;
public class InfoTest {
public String seeHello() {
return "Hello World";
}
}
3,在testjava工程加与flex通信环境:
解压blazeds-turnkey-3.2.0.3978.zip,找到里面的blazeds.war,将它导进testjava工程(右击WebContent>>import...>>File System 选上硬盘中你的blazeds.war地址>>finish)
编辑WEB-INF/flex/remoting-config.xml :
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<destination id="InfoTest ">//这个与flex 中的RemoteObject对应
<properties>
<!-- 写上完整的与flex通信的类名(包名+类名) -->
<source>cn.com.InfoTest </source>
</properties>
</destination>
</service>
再编辑web.xml:
4,将工程部署到tomcat上,并启动
5,在flex builder 中建一个flex project (名为testflex)
注意界面选项:a. Application type 选择 Web application(runs in Flash Player)
b. Server technology:
Application server type 选择J2EE 点next
c. Server location:
Root folder:选上testjava工程的地址(如 D:/project/testjava/WebContent)
Root URL:写上testjava工程的访问路径(如 “http://localhost:8080/testjava ”)
Context root: testjava(web工程名)其余的不用动直到finish
6,编辑testflex中的testflex.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.FaultEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function resultHandler(event:ResultEvent):void {
Alert.show(event.result.toString(), "连接成功");
}
private function faultHandler(event:FaultEvent):void {
Alert.show(event.fault.toString(), "连接失败");
}
]]>
</mx:Script>
<!-- destination 属性值就是testjava中 remoting-config.xml 中 destination 的 id -->
<mx:RemoteObject id="remoteObject"
destination="InfoTest "
result="resultHandler(event)"
fault="faultHandler(event)"/>
<mx:Button label="连接testjava" click="remoteObject.seeHello()" x="256.5" y="197"/>
</mx:Application>
7,最后选中testflex.mxml运行(Run Application) 即可
若无效果出现.....get flash,则你可用firefox查看效果试试(将flex开发工具属性中的的Web Browser选为firefox,并把flex--Profiler--Player/Browser 中配置flashPlay用firefox的exe文件)