使用 Flex 3.2 的 HTTPService/ResultEvent 与 Flex >= 3.5
通过设计决策或任何 Adobe 更改了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对此感兴趣,那么仔细阅读源代码会很有用。在 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
是一个内部类,因此它实际上是私有的,因此您需要转换为AbstractOperation
(mx.rpc.http.AbstractOperation
> 或mx.rpc.AbstractOperation
)。所以类似:
编辑:我收回它!看起来 Adobe 在构建 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 namedHTTPOperation
.It extends
mx.rpc.http.AbstractOperation
which in turn extendsmx.rpc.AbstractOperation
. InsideAbstractOperation
is a getter methodget 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 anAbstractOperation
(eithermx.rpc.http.AbstractOperation
ormx.rpc.AbstractOperation
).So something like:
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 variablehttpService
. I have no idea why they hide it from you but it looks like you'll have to keep your own reference around.我自己解决了这个问题。
HTTPService
中的一些属性可从AbstractOperation
获得。例如,我使用属性request
,它是一个对象:后来,当我得到在
event.currentTarget
中有HTTPOperation
的事件时,我得到我的HTTPService
以这种方式:I solved this problem for myself.
There are some properties in
HTTPService
that are available fromAbstractOperation
. For example, I use propertyrequest
which is an Object:And later, when I get Event which has
HTTPOperation
inevent.currentTarget
, I get myHTTPService
in such way: