Mega Code Archive

 
Categories / Flex / Components
 

Get selected item from Tree

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"     height="400">     <mx:Script>                  import mx.collections.XMLListCollection;         import mx.collections.ArrayCollection;         [Bindable]         public var myData:XML=         <catalog>             <category name="Meat">                 <product name="A" cost="4" isOrganic="No" isLowFat="Yes"/>                 <product name="B" cost="6" isOrganic="No" isLowFat="No"/>                 <product name="C" cost="1.5" isOrganic="Yes" isLowFat="No"/>             </category>         </catalog>;                  [Bindable]         public var listDP:XMLListCollection = new XMLListCollection(new XMLList());                  private function doTreeSelect():void         {             if (prodTree.selectedItem)                 listDP.addItem(prodTree.selectedItem.copy());         }         private function doListRemove():void         {             if (prodList.selectedItem)                 listDP.removeItemAt(prodList.selectedIndex);         }            </mx:Script>     <mx:Tree id="prodTree" dataProvider="{myData}" width="200" showRoot="false" labelField="@name" />     <mx:HBox>         <mx:Button id="treeSelect" label="Add to List" click="doTreeSelect()" />         <mx:Button id="listRemove" label="Remove from List" click="doListRemove()" />     </mx:HBox>     <mx:List id="prodList" dataProvider="{listDP}" width="200" labelField="@name" /> </mx:Application>