之前学了一些,今天边想边做,细节搞错了。整理一下,做个备忘。
(特别感谢大胡同志! 大胡是个好同志啊)
MyEclipse 6.5 + Tomcat 6.0 + Flex 3.2
Step 4 :
Step 6 :
这之后的HelloWorld项目创建步骤,网上有很多文章。我就借鉴一下:
index.mxml的代码为:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:TextInput id="txtName" x="109" y="102"/> <mx:Button click="sayHello()" label="Hello!" x="211" y="132"/> <mx:RemoteObject id="ro" destination="helloworld" result="resultHello(event)" fault="faultHello(event)"/> <mx:Script> <![CDATA[ import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.controls.Alert; [Bindable] private var helloResult:String; private function sayHello():void{ ro.sayHello(txtName.text); } private function resultHello(event:ResultEvent):void{ helloResult = event.result.toString(); Alert.show(helloResult); } private function faultHello(event:FaultEvent):void{ helloResult = event.fault.message.toString(); Alert.show(helloResult); } ]]> </mx:Script> </mx:Application>
在src目录下创建hello文件夹,创建HelloWorld.java类:
package hello; public class HelloWorld { public String sayHello(String name){ System.out.println("Hello, " + name); return "Hello, " + name ; } }
修改WebRoot\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="helloworld"> <properties> <source>hello.HelloWorld</source> </properties> </destination> </service>
基本就完事了。