setSubChecked Function get an error

In my project, I use this tree’s setSubChecked() function to set the the tree item’s selected status,But there pop up an error said that “can not find the parentObject or the parentObject is null”, I load this tree with LoadXML() function, everything are ok before run this function, I should be the AJAX request reason, the function was called before the tree load finished. When I add an Alert before the setSubChecked() function, the problem has gone. Who can help to reslove the problem? Many Thanks.

setSubChecked () method should be called after all items of the tree are loaded.

your are right, but how can I check the load finished status to make sure the setSubChecked Function was called after the loadXML function?

your are right, but how can I check the load finished status to make sure the setSubChecked Function was called after the loadXML function?

loadXML() method has several parameters. The second of it lets you to add needed methods that should be called after the loading is completed.
http://docs.dhtmlx.com/doku.php?id=dhtmlxtree:api_method_dhtmlxtreeobject_loadxml

For example:

mytree.loadXML("tree.xml",function(){ mytree.setSubChecked(id,true); });