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.
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 extendsmx.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.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: