flex mxml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="657" height="278" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
protected function button1_clickHandler(event:MouseEvent):void
{
obj.sayHello(text.text);
}
protected function method1_resultHandler(event:ResultEvent):void
{
result.text=event.result as String;
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="obj" destination="product" endpoint="/helloWorld/messagebroker/amf">
<s:method name="sayHello" result="method1_resultHandler(event)">
</s:method>
</s:RemoteObject>
</fx:Declarations>
<fx:Style>
#result{
fontSize:22;
fontWeight:bold;
fontFamily:"宋体";
color:#00e3e3;
}
</fx:Style>
<s:Button x="140" y="135" label="获取结果" click="button1_clickHandler(event)"/>
<s:Label id="result" x="285" y="68" width="235" height="36" backgroundAlpha="0.73"/>
<s:TextInput id="text" x="122" y="73"/>
<s:Label x="34" y="73" height="21" text="请输入您的姓名"/>
</s:Application>
/helloWorld/WebContent/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="product"><!-- 和<s:RemoteObject id="obj" destination="product“对应 -->
<properties>
<source>com.test.Product</source>
</properties>
</destination>
</service>