views:

296

answers:

1

Using Parsley, I have a service that I access through a [Command(selector='list')] public function getRssFeed( msg:RssEvent ):AsyncToken { return service.list() as AsyncToken; }

when I point to the "Real" RssService, everything works as expected. My problem is when I point to the "Mock" RssService. I can't figure out how to fake a AsyncToken with some dummy data return... does anyone knows how to do this ?

A: 

Resolved.............. ;)

 public function list():AsyncToken

     var rssFeed:Array = [rss,rss,rss];
     var token:AsyncToken = createToken(rssFeed);
     token.addResponder(new AsyncResponder(resultHandler, null));
     return token;

  }

  private function resultHandler(event:ResultEvent, token:AsyncToken = null):void
  {
     event.token.dispatchEvent(event);   
  }


  protected function createToken(result:Object):AsyncToken
  {
     var token:AsyncToken = new AsyncToken(null);
     setTimeout(applyResult, Math.random()*500, token, result);
     return token;
  }

  private function applyResult(token:AsyncToken, result:Object):void
  {
     mx_internal:token.setResult(result);
     var event:ResultEvent = new ResultEvent(ResultEvent.RESULT, false, true, result, token);
     mx_internal:token.applyResult(event);
     trace(token);
  }
Brett