Maybe on expand it has already calculated how many children it expects to see. I think there are lazy tree examples out there. If not, maybe I'll get around to posting one.
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of flex_geek Sent: Saturday, December 06, 2008 2:27 PM To: [email protected] Subject: [flexcoders] Tree has same number of items after expand but not after change Hi, all, In Flex 3 I have a Tree control that is doing dynamic loading of children. To simplify: I do a search that retrieves a root set of 15 folders. When I click on a folder, a function executes that retrieves the children and expands the folder to reveal them. This works correctly - the tree now displays the original 15 folders plus all the children of the folder I clicked on. On the other hand, if instead of clicking on the folder, I click on the plus sign (or on Mac the triangle) to the left of the folder, the folder opens and displays items, but the total number of items displaying in the tree is only 15 (the same number as the original number of folders) - so some of the folders disappear, and only a few children display in the open folder. If I close the folder using the minus and reopen it with the plus, all the items that should be displaying do then appear (i.e., the 15 folders plus all the children). What is odd is that I am using basically the same function for both events, the main difference being the event that is being passed to it. Here are the two functions: private function handleTreeChange( event:Event ):void { var selectedItem:Object = Tree( event.target ).selectedItem; if( selectedItem is FolderNode ) fetchFolderInfo( FolderNode( selectedItem ) ); } private function handleRetrieve( event:TreeEvent ):void { if( event.item is FolderNode && event.opening ) fetchFolderInfo( FolderNode( event.item) ); } private function fetchFolderInfo( folder:FolderNode ):void { //Items contains the children of the FolderNode //so if the folder already has items, don't go doing // the whole search thing if( folder.Items.length != 0 ) return; loadingPanel.visible = true; catalogTreeGenerator.getFoldersOrStyles(theRootDBName, folder.Id, theCatalogFKName); catalogTreeGenerator.addEventListener("nonRootItemsArrayReady", addFolderItems); function addFolderItems(e:Event):void{ folder.Items = new ArrayCollection(e.currentTarget.fsItems as Array ); catalogTree.validateNow(); catalogTree.expandItem( folder, true, true, false ); loadingPanel.visible = false; catalogTreeGenerator.removeEventListener ("nonRootItemsArrayReady", addFolderItems); } } Can anyone shed any light on why clicking on the plus next to a folder the first time (doing the handleRetrieve function triggered by "itemOpening" event) would cause the tree to only display a number of items equal to the original number of folders, when clicking on the folder itself (doing the handleTreeChange function triggered by "change" event) causes the tree to display all the appropriate items? Thanks very much for any help. -Flummoxed flex_geeklet

