Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Expanding a tree node


Published on

Expanding a Tree Node in Flex

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Expanding a tree node

  1. 1. Expanding a Tree Node Hemakumar.S Open Source Developer
  2. 2. Definition <ul><li>Tree control displays the root node or nodes of the tree when it first opens. If you want to expand a node of the tree when the tree opens, you can use the expandItem() method of the Tree control. The following change to the example in Handling Tree control events calls the expandItem() method as part of the Tree control's creationComplete event listener to expand the root node of the tree. </li></ul>
  3. 3. Cont…. <ul><li>At the tail end of Flex 3, several customers were in need of a Tree that could handle ItemPendingErrors. The shortest route to such a thing was to create a subclass of Tree that could handle the Advanced DataGrid's HierarchicalCollectionView. the acronym &quot;DMV&quot; throughout because the AdvancedDataGrid and HierarchicalCollectionView are part of the Data Management and Visualization package (which requires the Professional versions and/or more money) so those of you trying to go the cheap route won't be able to leverage this code. Also, you won't need this unless your data source throws ItemPendingErrors when an attempt is made to fetch data that hasn't been paged in yet, and unless you developed your own, you are using one of our data services which also cost you some money. </li></ul>
  4. 4. Source Code <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!-- dpcontrols/DrillIntoTree.mxml --> </li></ul><ul><li><mx:Application xmlns:mx=&quot;; layout=&quot;absolute&quot; creationComplete=&quot;initApp();&quot;> </li></ul><ul><li><mx:Script> </li></ul><ul><li><![CDATA[ </li></ul><ul><li>import mx.collections.XMLListCollection; </li></ul><ul><li>[Bindable] </li></ul><ul><li>private var treeData:XML = </li></ul><ul><li><root> <node label=&quot;Monkeys&quot;> </li></ul><ul><li><node label=&quot;South America&quot;> </li></ul><ul><li><node label=&quot;Coastal&quot;/> </li></ul><ul><li><node label=&quot;Inland&quot;/> </li></ul><ul><li></node> ] </li></ul><ul><li><node label=&quot;Africa&quot; isBranch=&quot;true&quot;/> </li></ul><ul><li><node label=&quot;Asia&quot; isBranch=&quot;true&quot;/> </li></ul><ul><li></node> </li></ul>
  5. 5. Cont…. <ul><li><node label=&quot;Sharks&quot;> </li></ul><ul><li><node label=&quot;South America&quot; isBranch=&quot;true&quot;/> </li></ul><ul><li><node label=&quot;Africa&quot; isBranch=&quot;true&quot;/> </li></ul><ul><li><node label=&quot;Asia&quot; > </li></ul><ul><li><node label=&quot;Coastal&quot;/> </li></ul><ul><li><node label=&quot;Inland&quot;/> </li></ul><ul><li></node> </li></ul><ul><li></node> </li></ul><ul><li></root> </li></ul><ul><li>private var openSequence:Array = []; </li></ul><ul><li>private function initApp():void </li></ul><ul><li>{ </li></ul><ul><li>var paramLength:int = 0; </li></ul><ul><li>for (var s:String in Application.application.parameters) </li></ul><ul><li>{ if (!isNaN(Number(s))) </li></ul><ul><li>{ openSequence[s] = Application.application.parameters[s]; paramLength += 1; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  6. 6. Cont…. <ul><li>openTree(); </li></ul><ul><li>} </li></ul><ul><li>private function openTree(): </li></ul><ul><li>void </li></ul><ul><li>{ </li></ul><ul><li>var nodeList:XMLListCollection = myTree.dataProvider as XMLListCollection; var node:XMLList = nodeList.source; </li></ul><ul><li>for(var i:int=0; i < openSequence.length; i++) </li></ul><ul><li>{ var j:int = openSequence[i]; </li></ul><ul><li>var n:XML = node[j]; </li></ul><ul><li>if( n.children() != null ) </li></ul><ul><li>{ myTree.expandItem(n,true,false); </li></ul><ul><li>node = n.children(); </li></ul><ul><li>} </li></ul><ul><li>else { break; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  7. 7. Cont…. <ul><li>if( n != null ) myTree.selectedItem = n; </li></ul><ul><li>} </li></ul><ul><li>]]> </li></ul><ul><li></mx:Script> </li></ul><ul><li>mx:Tree id=&quot;myTree&quot; y=&quot;50&quot; width=&quot;221&quot; height=&quot;257&quot; horizontalCenter=&quot;0&quot; dataProvider=&quot;{treeData.node}&quot; labelField=&quot;@label&quot;/> </li></ul><ul><li></mx:Application> </li></ul>
  8. 8. Screen Shot
  9. 9. Thank You....