Re: [flexcoders] Flex 2 addTreeNode

2006-02-07 Thread Hari Kolasani






I think , the Flex 2.0 Tree related classes have been changed quite a
bit with the introduction of Hierarchical Data Providers and stuff. 

Here is some sample .mxml/as code that worked for me. Hope this will
help.

- Hari

*
?xml version="1.0" encoding="utf-8"?
mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"
backgroundColor="#FF" creationComplete="initList()"
 mx:Script
  ![CDATA[
  import mx.collections.XMLListCollection;
  
  var origXML:XML;

  public function initList() 
  {
   myTree.rootVisible = false;

   //TODO: Get this XML from a data service
   var origXMLString:String = "MyRoot " + 
   "node1
label=\"supernode1\" someProp=\"sdsdf \" isBranch=\"true\"/" + 
   "node2
label=\"supernode2\" someProp=\"sdsdf \" isBranch=\"true\"/" + 
   "node3
label=\"supernode3\" someProp=\"sdsdf \" isBranch=\"true\"/" + 
  "/MyRoot";
   
   origXML = new XML(origXMLString);
   myTree.dataProvider = origXML;
  }
  public function open(event:Object)
  {
   var selectedNode:Object =event.node;
   
   var myXMLList:XMLList = new XMLList(selectedNode);
   
   //TODO: Get this XML from a data service
based on the selected node.
   var newXMLString:String = "childnode1
label=\"childnode1\" someProp=\"sdsdf \" isBranch=\"true\" /" + 
 "childnode2
label=\"childnode2\" someProp=\"sdsdf \" isBranch=\"false\" /" + 
  "childnode3
label=\"childnode3\" someProp=\"sdsdf \" isBranch=\"true\" /" ; 
   
   var myNewXMLList:XMLList = new XMLList(newXMLString);
   
   selectedNode.setChildren(myNewXMLList);
   
   myText1.text = selectedNode.toXMLString();
   myText2.text = myTree.dataProvider.source[0];
   myTree.dataProvider = origXML;
  }
  
  public function close(event:Object)
  {
   var selectedNode:Object = event.node;
   
   var myXMLList:XMLList = new XMLList(selectedNode);
   
   removeAllDecendants(myXMLList);
   
   myText1.text = selectedNode.toXMLString();
   myText2.text = myTree.dataProvider.source[0];
   myTree.dataProvider = origXML;
  }
  
  public function removeAllDecendants(xmlList:XMLList)
  {
   var myDescendantXMLList:XMLList = xmlList.descendants();
   var myDecendentXMLListCollection:XMLListCollection = new
XMLListCollection(myDescendantXMLList);
   myDecendentXMLListCollection.removeAll();
  }

 ]]
 /mx:Script

 !-- Simple example to demonstrate the Tree control --
 mx:XML id="myxml"
 /mx:XML

 mx:HDividedBox width="100%" height="100%"

 !-- Tree listing of directories (only) --
 mx:Box
mx:Tree id="myTree" width="600" height="600"
labelField="@label" defaultLeafIcon="@Embed('images/folder.gif')"
nodeOpen="open(event)" nodeClose="close(event)"/
 /mx:Box

  mx:VBox
  !-- Text Areas to Display Node XMLs --
  mx:Box
   mx:TextArea width="600" height="300" id="myText1"
/
  /mx:Box
 mx:Box
   mx:TextArea width="600" height="300" id="myText2"
/
  /mx:Box
 /mx:VBox
 /mx:HDividedBox
/mx:Application
*

Brendan Meutzner wrote:

Hi,
  
Can someone provide me with an example of addTreeNode for Flex 2? I
have a XML structure that is loaded into my Tree as the dataProvider.
I would like to be able to click on a node within the tree, and then
add a sub node into that selected node. When I get the selectedNode
from the tree, and attempt call addTreeNode on it, I get an error
"Call attempted on an object that is not a function"...
  
Unfortunately, not much documentation on these methods yet, so any
help offered would be very much appreciated.
  
Brendan
  
  
  
  
  








--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com








  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  










Re: [flexcoders] Flex 2 addTreeNode

2006-02-07 Thread Jason Y. Kwong



To answer your specific question about adding nodes... Since you have an XML dataProvider, the selectedNode property will return an XML object. You can then use the appendChild() method to add child nodes. eg:


var node: XML = XML(tree.selectedNode);
node.appendChild(node label=newchild);
On 2/5/06, Brendan Meutzner [EMAIL PROTECTED]
 wrote: 
Hi,Can someone provide me with an example of addTreeNode for Flex 2?Ihave a XML structure that is loaded into my Tree as the dataProvider. 
I would like to be able to click on a node within the tree, and thenadd a sub node into that selected node.When I get the selectedNodefrom the tree, and attempt call addTreeNode on it, I get an errorCall attempted on an object that is not a function... 
Unfortunately, not much documentation on these methods yet, so anyhelp offered would be very much appreciated.Brendan--Flexcoders Mailing ListFAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txtSearch Archives: 
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links * To visit your group on the web, go to: 
http://groups.yahoo.com/group/flexcoders/* To unsubscribe from this group, send an email to:  
[EMAIL PROTECTED]* Your use of Yahoo! Groups is subject to: 
http://docs.yahoo.com/info/terms/ 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com








  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  









[flexcoders] Flex 2 addTreeNode

2006-02-05 Thread Brendan Meutzner
Hi,

Can someone provide me with an example of addTreeNode for Flex 2?  I
have a XML structure that is loaded into my Tree as the dataProvider.
 I would like to be able to click on a node within the tree, and then
add a sub node into that selected node.  When I get the selectedNode
from the tree, and attempt call addTreeNode on it, I get an error
Call attempted on an object that is not a function...

Unfortunately, not much documentation on these methods yet, so any
help offered would be very much appreciated.

Brendan






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/