Demo2.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.ResultEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
private function clickHandler():void
{
myRo.addEventListener(ResultEvent.RESULT,resultHandler);
myRo.addEventListener(FaultEvent.FAULT,faultHandler);
myRo.getString(ti.text);//调用后台java类的方法名
}
private function resultHandler(event:ResultEvent):void
{
myRo.removeEventListener(ResultEvent.RESULT,resultHandler);
ta.text = event.result as String;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.message.toString());
}
]]>
</mx:Script>
<mx:RemoteObject id="myRo"
destination="remotjava"/>
<mx:Button x="223"
y="42"
label="Button"
click="clickHandler()"/>
<mx:TextInput x="39"
y="42"
id="ti"/>
<mx:TextArea x="39"
y="115"
width="406"
height="141"
id="ta"/>
</mx:Application>
<?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.ResultEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
private function clickHandler():void
{
myRo.addEventListener(ResultEvent.RESULT,resultHandler);
myRo.addEventListener(FaultEvent.FAULT,faultHandler);
myRo.getString(ti.text);//调用后台java类的方法名
}
private function resultHandler(event:ResultEvent):void
{
myRo.removeEventListener(ResultEvent.RESULT,resultHandler);
ta.text = event.result as String;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.message.toString());
}
]]>
</mx:Script>
<mx:RemoteObject id="myRo"
destination="remotjava"/>
<mx:Button x="223"
y="42"
label="Button"
click="clickHandler()"/>
<mx:TextInput x="39"
y="42"
id="ti"/>
<mx:TextArea x="39"
y="115"
width="406"
height="141"
id="ta"/>
</mx:Application>
后台Java类:Test.java
package cn;
public class Test {
public String getString(String string){
return "Hello---------"+string;
}
}
remoting-config.xml:
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<destination id="remotjava">
<properties>
<source>cn.Test</source>
</properties>
</destination>