在Flex中调用Java函数
现在我正在尝试了解 Flex 如何与 Java 配合使用(Flex -> BlazeDS -> Java)。 我尝试遵循这个教程和所有内容工作正常,我只是不明白为什么我们需要这样调用java函数:
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
// Send the message in response to a Button click.
private function echo():void {
var text:String = ti.text;
remoteObject.echo(text);
}
// Handle the recevied message.
private function resultHandler(event:ResultEvent):void {
ta.text += "Server responded: "+ event.result + "\n";
}
// Handle a message fault.
private function faultHandler(event:FaultEvent):void {
ta.text += "Received fault: " + event.fault + "\n";
}
]]>
</mx:Script>
为什么我们需要使用Event/ResultEvent来调用Java函数。 为什么不直接做这样的事情:
EchoService.echo("hi")
谢谢
Right now I'm trying to understand how Flex works with Java (Flex -> BlazeDS -> Java).
I tried to follow THIS tutorial and everything works fine, I just don't understand why do we need to call java function this way:
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
// Send the message in response to a Button click.
private function echo():void {
var text:String = ti.text;
remoteObject.echo(text);
}
// Handle the recevied message.
private function resultHandler(event:ResultEvent):void {
ta.text += "Server responded: "+ event.result + "\n";
}
// Handle a message fault.
private function faultHandler(event:FaultEvent):void {
ta.text += "Received fault: " + event.fault + "\n";
}
]]>
</mx:Script>
Why do we need to use Event/ResultEvent in order to call Java function. Why not just to do something like this:
EchoService.echo("hi")
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它能够处理服务器延迟和其他异常情况。 如果您只是调用该方法,您的 UI 将在服务器传输期间冻结。 通过回调,UI 可以继续处理事件,直到收到数据并准备好查看为止。
It is to be able to handle server lag and other anomalous conditions. If you just called the method, your UI would freeze during the server transfer time. With the callback, the UI can continue to process events until the data has been received and is ready to be viewed.
根据成功或错误使用两种单独的方法将使您的程序在服务器以某种方式出错时做出不同的反应。
Having two separate methods depending of success or fault will allow your program to react differently if the server errors in some way.