再帰的に呼び出される関数を作成しました。イベントのリスナーで値がプッシュされる配列を維持しました。ただし、問題は、関数が配列のインクリメントなしで最初に返され、リスナーが後で実行されることです。
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;
}
イベントの完了後に関数が戻るように、この問題を解決する方法はありますか?