Typically, this is done via a customized ITreeDataDescriptor.  It should always 
return true for isBranch and hasChildren, and return an empty ArrayCollection 
for getChildren that you fill later with the actual children.

From: [email protected] [mailto:[email protected]] On Behalf 
Of Dan Vega
Sent: Friday, December 19, 2008 7:35 PM
To: [email protected]
Subject: [flexcoders] Tree problems


I am still having some tree / array issues that I am hoping to get some help 
on. My tree loads an array of data that looks like this. Items with a children 
array tell me that this folder should be a branch and it has children. When you 
click on the branch I want to go retrieve the list of directories for that 
folder and update the array with the new directory data.

(Array)#0
  [0] (Object)#1
    lastModified = 1225560062218
    name = "bin"
    parent = "H:\JRun4"
    path = "H:\JRun4\bin"
  [1] (Object)#2
    children = (Array)#3
    lastModified = 1186192523437
    name = "docs"
    parent = "H:\JRun4"
    path = "H:\JRun4\docs"

My itemOpen listener event basically get the path of the folder being opened 
and fetch the directories for that path.

            private function onItemOpen(event:TreeEvent):void {
                var path:String = event.item.path;
                holder = event.item.children;
                FileManager.getDirectories(path);
            }

When the list of directories is called this method is the result handler. IF 
the tree data provider is null we know its top level. What I thought I could do 
is setup a variable called holder that would the array object of the item 
above. I thought this would pass the reference of that object and using that 
reference i could set the new dirs into that empty array. This is not really 
working so I was wondering if anyone has some ideas or what the right approach 
should be.

            private function listDirectories(event:ResultEvent):void {
                var dirs:Array = event.result as Array;

                // if the _directories array is null this is our root request
                if(_directories == null) {
                    _directories = dirs;
                }else {
                    // what do we do now?
                    holder = dirs;
                }
            }

Thanks for the help!


Thank You
Dan Vega
[email protected]<mailto:[email protected]>
http://www.danvega.org

Reply via email to