Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    Programatically create XMLListCollection???

    Hi guys,

    I've been trying to figure this one out for a while and can't seem to get my head round it. I'm trying to build a dynamic tree from a cfdirectory query, I've looked all over but can't find a good solution, so I'm giving it a go in AS3.

    I've got the arraycollection that's returned from the server via RemoteObject.

    What i want to do is loop over this and select only objects with certain properties, and build my XMLListCollection in AS3 before i send it to the tree.

    So, i have the initial loop of the array collection where i want to extract the directories only, pop them into the XMLListCollection as top level nodes, then loop back through the same thing over and over until i rebuild the heirachy data that the root folder looks like, then finally send it to the tree (fingers crossed!)

    So, here's what i got so far:
    Code:
    private function rhServer(event:ResultEvent):void{
    				treeAC = event.result as ArrayCollection;
    				var treeXML:XMLListCollection =  new XMLListCollection;
    				var AC:ArrayCollection = new ArrayCollection;
    				var i:int
    				for (i = 0; i < treeAC.length; i ++){
    					if(treeAC.getItemAt(i).Type == "Dir" ){
    						AC.addItem(treeAC.getItemAt(i).Name);
    						trace (treeAC.getItemAt(i).Name);
    					}
    				}
    			}
    This lets me populate at AC ArrayCollection with the four folders that happen to be in the root folder, but i've tried the same method with addItem on the XMLListCollection and i keep getting errors, it just wont let me construct an XMLListCollection from scratch.... where am i going wrong?

    Here's the code that returns the error:
    Code:
    			private function rhServer(event:ResultEvent):void{
    				treeAC = event.result as ArrayCollection;
    				var treeXML:XMLListCollection =  new XMLListCollection;
    				var i:int
    				for (i = 0; i < treeAC.length; i ++){
    					if(treeAC.getItemAt(i).Type == "Dir" ){
    						treeXML.addItem(treeAC.getItemAt(i).Name);
    						trace (treeAC.getItemAt(i).Name);
    					}
    				}
    			}
    So what i'm aiming for here is to create an XMLListCollection that'll read something like:

    parent folder
    .....chid folder
    ..........child file
    .....child file
    parent folder
    .....child file
    .....child file
    parent folder
    .....child folder
    ..........child file
    file
    file
    file


    etc etc.

    So the question is can i build an XMLListCollection from scratch programatically?

    Any help will be very gratefully received!

    Many thanks in advance all

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    Update

    ok, so i'm getting there slowly....

    The problem i have now is that when i create the XML with this code it adds a child with the same value to the folder (node? branch? not sure )

    Code:
    private function rhServer(event:ResultEvent):void{
    				treeAC = event.result as ArrayCollection;
    				var treeXML:XMLListCollection =  new XMLListCollection;
    				var i:uint
    				for (i = 0; i < treeAC.length; i ++){
    					if(treeAC.getItemAt(i).Type == "Dir" ){
    						var d:XML = <folder/>; //called var 'd' to remind me it's a directory, so should have childern eventually...
    						d.appendChild(treeAC.getItemAt(i).Name); 
    						treeXML.addItem(d);
    						trace (d.toXMLString());
    						trace ("Trace name of directory = " + treeAC.getItemAt(i).Name);
    					}
    				}
    				directoryTree.dataProvider = treeXML;
    			}
    so this gives me a result like:

    parent folder
    .....parent folder copy (but as a child of folder)
    parent folder
    .....parent folder copy (but as a child of folder)
    parent folder
    .....parent folder copy (but as a child of folder)

    Does that make sense? It's creating a folder correctly, but then places a child/file inside each folder and replicates it's name....

    Does anyone know what's going wrong here???

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •