使用 Flex 3.2 的 HTTPService/ResultEvent 与 Flex >= 3.5

发布于 2024-09-04 23:20:58 字数 1039 浏览 11 评论 0原文

通过设计决策或任何 Adob​​e 更改了 HTTPService 对象触发的 ResultEvent 的内容。

看一下下面的示例:

var httpService:HTTPService = myHTTPServices.getResults();
httpService.addEventListener(ResultEvent.RESULT,resultHandler);
httpService.send();

/**
 * Handels the login process
 */
function resultHandler(event:ResultEvent):void
{
    // get http service
    var httpService = (event.target as HTTPService);

    // do something
}

它与 Flex 3.2 一起工作就像一个魅力。但是当我尝试使用 Flex 3.5 或 Flex 4.0 编译它时,event.target as HTTPService 为空。

我发现 event.target 现在是 HTTPOperation 的一个实例。这很有趣,因为我在 langref 中找不到 HTTPOperation。不过,我认为Flash Builder的调试器意味着mx.rpc.http.Operation

调试器还显示 event.target 有一个私有属性 httpService,这是我期望通过 event.target 获得的实例。但它是私有的,因此 event.target.httpService 不起作用。

如果我只想删除 EventListener,我可以将 event.target 转换为 EventDispatcher。但我需要使用 HTTPService 中的方法。

那么:如何从 ResultEvent 获取 HTTPService 实例?

任何帮助将不胜感激。谢谢!

J。

through a design decission or what-so-ever Adobe changed the content of the ResultEvent fired by a HTTPService Object.

Take a look at following example:

var httpService:HTTPService = myHTTPServices.getResults();
httpService.addEventListener(ResultEvent.RESULT,resultHandler);
httpService.send();

/**
 * Handels the login process
 */
function resultHandler(event:ResultEvent):void
{
    // get http service
    var httpService = (event.target as HTTPService);

    // do something
}

It works like a charm with Flex 3.2. But when I try to compile it with Flex 3.5 or Flex 4.0 event.target as HTTPService is null.

I figured out that event.target is now an instance of HTTPOperation. That is interesting because I can't find HTTPOperation in the langref. However, I think what Flash Builder's debugger means is mx.rpc.http.Operation.

The debugger also shows that event.target has a private attribute httpService which is the instance I expected to get with event.target. But it's private, so event.target.httpService doesn't work.

If I only want to remove the EventListener I can cast event.target as EventDispatcher. But I need to use methods from HTTPService.

So: How can I get the HTTPService instance from the ResultEvent?

Any help would be appreciated. Thanks!

J.

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

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

发布评论

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

评论(2

手心的海 2024-09-11 23:20:58

如果您对此感兴趣,那么仔细阅读源代码会很有用。在 OS X 上,rpc 类位于:/Applications/Adobe Flash Builder Beta 2/sdks/3.4.1/frameworks/projects/rpc/src

Inside mx .rpc.http.HTTPService 确实有一个名为 HTTPOperation 的内部类。
它扩展了 mx.rpc.http.AbstractOperation,而 mx.rpc.http.AbstractOperation 又扩展了 mx.rpc.AbstractOperation。 AbstractOperation 内部是一个 getter 方法 get service,它看起来会返回您需要的内容。

由于 HTTPService 是一个内部类,因此它实际上是私有的,因此您需要转换为 AbstractOperationmx.rpc.http.AbstractOperation > 或 mx.rpc.AbstractOperation)。

所以类似:

function resultHandler(event:ResultEvent):void
{
    // get the operation
    var operation:AbstractOperation = AbstractOperation(event.target);

    // get http service
    var httpService:HTTPService = HTTPService(operation.service);
}

编辑:我收回它!看起来 Adob​​e 在构建 HTTPOperation 时调用 super 时正在为服务发送 null。因此,HTTPService 仅缓存在私有变量 httpService 中。我不知道他们为什么向你隐藏它,但看起来你必须保留自己的参考资料。

It is useful to go through the source if you get into this. On OS X the rpc classes are here: /Applications/Adobe Flash Builder Beta 2/sdks/3.4.1/frameworks/projects/rpc/src

Inside mx.rpc.http.HTTPService there is indeed an inner-class named HTTPOperation.
It extends mx.rpc.http.AbstractOperation which in turn extends mx.rpc.AbstractOperation. Inside AbstractOperation is a getter method get service which looks to return what you need.

Since HTTPService is an inner-class it is effectively private so you'll need to cast to an AbstractOperation (either mx.rpc.http.AbstractOperation or mx.rpc.AbstractOperation).

So something like:

function resultHandler(event:ResultEvent):void
{
    // get the operation
    var operation:AbstractOperation = AbstractOperation(event.target);

    // get http service
    var httpService:HTTPService = HTTPService(operation.service);
}

edit: I take it back! Looks like Adobe is sending null for the service when it calls the super when constructing the HTTPOperation. The HTTPService is therefore only cached in the private variable httpService. I have no idea why they hide it from you but it looks like you'll have to keep your own reference around.

不顾 2024-09-11 23:20:58

我自己解决了这个问题。
HTTPService 中的一些属性可从 AbstractOperation 获得。例如,我使用属性request,它是一个对象:

myService.request["service"] = myService;

后来,当我得到在event.currentTarget中有HTTPOperation的事件时,我得到我的 HTTPService 以这种方式:

 var eventService : HTTPService = HTTPService( AbstractOperation( event.currentTarget ).request["service"] );

I solved this problem for myself.
There are some properties in HTTPService that are available from AbstractOperation. For example, I use property request which is an Object:

myService.request["service"] = myService;

And later, when I get Event which has HTTPOperation in event.currentTarget, I get my HTTPService in such way:

 var eventService : HTTPService = HTTPService( AbstractOperation( event.currentTarget ).request["service"] );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文