Services and handlers/responders
Hi!
I have made a service encapsulated inside a Class with a method
like so:
public function load(url:String,responder:Function):void
{
_service.url = url;
var token:AsyncToken = _service.send();
token.addResponder(new mx.rpc.Responder(function (event:ResultEvent):void{
responder(event);
_service.url=null;
token = null;
}, handleServiceFault));
}
Then, inside a command, I inject that service :
public class LoadPageCommand extends ModuleCommand
{
[Inject]
public var inEvent:PageEvent;
[Inject]
public var serviceLoader:EpodxLoaderService;
...
And inside my execute method call the load method from that service and set a handleComplete that 'll be called each time result is received :
override public function execute():void
{
service.load(inEvent.page.url,handleComplete);
}
public function handleComplete(event:ResultEvent):void
{ .... }
The reason why I want a callback function is to access my event
payload which contains the Value objects I want to work on ...
I'm sure all I did is conceptually good ...
thanks
Comments are currently closed for this discussion. You can start a new one.
2 Posted by peter.bannier on 18 May, 2011 03:28 PM
erratum :
I'm not sure it is good!
3 Posted by Jos Yule on 18 May, 2011 04:50 PM
Well, you can explicitly "hold" a command, or rather, make it async-friendly, using the
commandMap.detain(this) and commandMap.release(this).
Rather then using the callback to "hold" the reference.
j
Stray closed this discussion on 08 Jun, 2011 10:00 AM.