I create a mx:tree with flex and its data provider is an array collection. In addition, this array collection is set by using a database. This process is handled with an event listener function. Database returns data to array collection asynchronously. And this is the problem that when flex application is started array collection is not fully initialized. Hence, mx:tree is incomplete. Here is the code segment:
protected function populateTreeNode(node:Object):void
{
if (node != null && node["className"] != "InventoryCategory") return;
var categoryId:Number = 0;
if (node != null)
categoryId = node["id"];
DAOUtil.loadAll("InventoryCategory", EventUtil.handleWithArgs(popoluateTreeNodeHandler, [node, "InventoryCategory"]), "categoryId", categoryId.toString());
DAOUtil.loadAll("InventoryItem", EventUtil.handleWithArgs(popoluateTreeNodeHandler, [node, "InventoryItem"]), "categoryId", categoryId.toString());
}
protected function popoluateTreeNodeHandler( event : Event , nodeCategory:Object, typeName:String): void
{
var items:Array = DAOUtil.getArray(event, typeName);
items = LangUtil.fromNameField(items);
if (nodeCategory != null)
nodeCategory["children"] = items;
else
inventoryArray.addAll(new ArrayCollection(items));
for each (var item:Object in items) populateTreeNode(item);
}
This function tries to initialize array collection recursively and at the end of the populateTreeNodeHandler function it is fully initialized. But when flex application is started, it is sometimes incomplete. Is there any solution to this problem?