云南移动经分系统的复杂报表用到了flex,之前这块我也碰不到,不过日后会有些接触,flex做出来的报表确实要好看些,趁周末了解下Flex Builder4怎么用的,网上搜了一大堆的资料,好不容易才调试成功,这里作个笔记以免忘记了。
要使用的主要有MyEclipse 8.0/Flex Builder 4/blazeds(当然会用到tomcat,jdk,browser这些哈,这个是java程序员必须的)
1.建立一个javaweb项目tt
写了发现图片看不到,用文字补充:包名为com.demo
package com.demo;
public class HelloWorld {
public String sayHello(String name) {
return "hello," + name;
}
} 2.解压blazeds,复制WEB-INF文件夹,覆盖掉你的Test工程下的WebRoot下的WEB-INF文件夹。打开Test工程下的WebRoot\WEB-INF\flex\remoting-config.xml这个文件,插入以下代码:
<destination id="Hello"> <properties> <source>com.demo.HelloWorld</source> </properties> </destination>
插入后的效果:
<?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> <destination id="Hello"> <properties> <source>com.demo.HelloWorld</source> </properties> </destination> <default-channels> <channel ref="my-amf" /> </default-channels> </service>
3.打开Flex Builder 4,鼠标右键新建一个名为tt的flex项目:
填写项目名称;项目位置默认;应用程序类型选择Web(在Adobe Flash Player 中运行)(W);Flex SDK 版本使用默认SDK
点击“下一步”
在输出文件夹(指定输出路径)里,选择刚才建立的javaweb项目tt 的WebRoot目录,点击“完成”。
tt.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.rpc.events.ResultEvent;
[Bindable]
private var helloResult:String;
private function Hello():void {
srv.sayHello(inputText.text); //通过RemoteObject的对象test,直接调用Java端的方法
}
private function resultHandler(event:ResultEvent):void {
helloResult = event.result as String;
}
]]>
</mx:Script>
<mx:RemoteObject id="srv" destination="Hello"
result="resultHandler(event)" endpoint="/tt/messagebroker/amf" />
<mx:Label text="输入文字" id="nameLabel" x="19" y="277" />
<mx:TextInput id="inputText" x="78" y="277" />
<mx:Button label="HelloWord" id="Button" click="Hello()" x="101"
y="308" />
<mx:HBox x="10" y="10" width="1155" height="379" >
<mx:TextArea width="705" height="237" text="{helloResult}" fontSize="13" fontWeight="bold" color="#FA7A08" />
</mx:HBox>
</mx:Application>
destination="Hello" :destination属性值必须和
remoting-config.xml中的destination的id一样;
endpoint="/tt/messagebroker/amf" :/tt/就是javaweb项目tt 的名称
在MyEclipose下刷新tt工程,会在WebRoot下看到生成的新文件保存项目,发布到Tomcat,启动Tomcat服务,在IE中输入
http://localhost:8080/tt/tt.html 就能看到效果了!
这里返回的只是一个简单的字符串,这个字符串是从HelloWorld的sayHello()方法返回的,至于你要让这个方法做什么后再返回,就自己写了;
本文介绍如何使用FlexBuilder4与BlazeDS搭建交互式应用。通过具体步骤展示如何配置环境、创建Flex项目并与Java后端进行通信,实现一个简单的远程调用示例。
7204

被折叠的 条评论
为什么被折叠?



