1 Reply Latest reply on May 28, 2010 5:28 AM by Dajji

    Regarding Tree Item close event

    Karthik@Chennai Level 1

      Hi All,

      We have a Tree dataprovider with more than 3 levels, while collapsing tree root node, close event is not happening properly(Issue is selectedItem is not setting to root node instead maintaining at previously selected child item).

      Please give me an solution to over come this problem.

       

      regards,

      karthik

        • 1. Re: Regarding Tree Item close event
          Dajji Level 3

          You can try following sample.

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <!-- Tree control example. -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          
              <mx:Script>
                  <![CDATA[
                       import mx.events.TreeEvent;
          
                      [Bindable]
                      public var selectedNode:XML;
          
                      // Event handler for the Tree control change event.
                      public function treeChanged(event:Event):void {
                          selectedNode=Tree(event.target).selectedItem as XML;
                      }
                      
                      private function itemClose_Handler(e:TreeEvent):void{
                           selectedNode = e.item as XML;
                      }
                  ]]>
              </mx:Script>
          
              <mx:XMLList id="treeData">
                  <node label="Mail Box">
                      <node label="Inbox">
                          <node label="Marketing"/>
                          <node label="Product Management"/>
                          <node label="Personal"/>
                      </node>
                      <node label="Outbox">
                          <node label="Professional"/>
                          <node label="Personal"/>
                      </node>
                      <node label="Spam"/>
                      <node label="Sent"/>
                  </node>    
              </mx:XMLList>
          
              <mx:Panel title="Tree Control Example" height="75%" width="75%" 
                  paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
          
                  <mx:Label width="100%" color="blue" 
                      text="Select a node in the Tree control."/>
          
                  <mx:HDividedBox width="100%" height="100%">
                      <mx:Tree id="myTree" width="50%" height="100%" labelField="@label"
                          showRoot="true" dataProvider="{treeData}" change="treeChanged(event)" itemClose="itemClose_Handler(event)"/>
                      <mx:TextArea height="100%" width="50%"
                          text="Selected Item: {selectedNode.@label}"/>
                  </mx:HDividedBox>
                  
              </mx:Panel>
          </mx:Application>