我写了一个递归调用的函数。我维护了一个数组,其中的值是通过事件的侦听器推送的。但问题是函数在没有数组增量的情况下首先返回,并且稍后执行侦听器。
public function getAllChilds(seltem:XML, allChilds:Array): Array
{
if(//the childs of selected item if need to retrive from server)
var viewChildrenJobsService : HTTPService = new HTTPService();
viewChildrenJobsService.url = // here is my url ;
viewChildrenJobsService .addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void {
// now on this result event i got all childs of selected item.
for each(var childJob :XML in seltem.children())
{
allChilds.push(childJob);
if (//the childs of childJob need to retrive from server)
allChilds = getAllHierarchicalChilds(childJob, allChilds);
}
});
return allChilds;
}
有什么办法可以解决这个问题,让函数在事件完成后返回?