AsyncToken返回基本字符串?

发布于 2024-12-21 17:53:14 字数 734 浏览 2 评论 0原文

我正在尝试开发 Flex Mobile / PHP 应用程序,但我在使用 AsyncToken 时遇到了一些麻烦...它不只是返回一个基本字符串吗?

例如...我只想从我的请求返回一个简单的字符串结果 - 现在,它将从已实现的方法返回一个基本输出字符串。后端部分可以工作(PHP),我已经完成了所有这些...这给我带来了一些问题:

import mx.rpc.AsyncResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function button_clickHandler(event:MouseEvent):void
{
    loginResult.token = user_service.login();
    loginResult.token.addResponder(new AsyncResponder(onResult,onFault));
}

public function onResult(event:ResultEvent, token:Object):void
{
    // what would i do here??
}

public function onFault(event:FaultEvent,token:Object):void
{
    txtResult.text = event.fault.faultDetail;
}

它非常简单 - 任何建议或建议肯定会有所帮助!谢谢你!

I'm trying to develop a Flex Mobile / PHP application, and I'm running into some trouble with the AsyncToken... Does it not just return a basic string?

For example... I'm wanting to just return a simple string result from my request - right now, it's going to return a basic output string from the method that's implemented. The backend part works (PHP), I've done all of that... It's this that's giving me some problems:

import mx.rpc.AsyncResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function button_clickHandler(event:MouseEvent):void
{
    loginResult.token = user_service.login();
    loginResult.token.addResponder(new AsyncResponder(onResult,onFault));
}

public function onResult(event:ResultEvent, token:Object):void
{
    // what would i do here??
}

public function onFault(event:FaultEvent,token:Object):void
{
    txtResult.text = event.fault.faultDetail;
}

It's pretty straightforward - any suggestions, or recommendations would surely help! Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2024-12-28 17:53:14

很容易。 ResultEvent#result 属性包含远程服务返回的值。您需要做的就是将其转换为正确的类型(因为默认情况下它是一个对象)。

例如,处理返回字符串的服务方法:

public function onResult(event:ResultEvent):void {
    var s:String = event.result as String;
}

对于其他类型也是如此:

var a:Array = event.result as Array;

或者甚至更复杂的自定义类:

var instance:MyClass = event.result as MyClass;

请注意,最后一个示例仅适用于 AMF 远程处理;您必须在客户端和服务器端具有相同的类定义;并且您必须通过在 AS 类定义上使用 [RemoteClass(alias="net.riastar.MyClass")] 元数据标记让它们知道彼此的存在。在服务器端如何处理这个问题取决于那里使用的语言。

Easy enough. The ResultEvent#result property contains the value returned by the remote service. All you need to do is cast it to the right type (since it is an Object by default).

For instance, handling your service method that returns a String:

public function onResult(event:ResultEvent):void {
    var s:String = event.result as String;
}

Same goes for other types:

var a:Array = event.result as Array;

Or even more complex custom classes:

var instance:MyClass = event.result as MyClass;

Note that this last example will only work with AMF remoting; you have to have the same class definition on the client side and on the server side; and you have to let them know of each other's existence by using the [RemoteClass(alias="net.riastar.MyClass")] metadata tag on your AS class definition. How you have to handle this on the server side depends on the language used there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文