使用欧芹,
我有一项服务,可以通过
[Command(selector ='list')]
公共函数getRssFeed(msg:RssEvent):AsyncToken
{
返回service.list()作为AsyncToken;
}
当我指向“真实” RssService时,一切都按预期工作。我的问题是当我指向“模拟” RssService时。我不知道如何用一些伪数据返回来伪造AsyncToken ...有人知道怎么做吗?
最佳答案
解决.............. ;)
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);
}