Try this -

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">

<mx:Script>

  <![CDATA[

  import mx.collections.XMLListCollection;

  import mx.events.TreeEvent;

  import mx.controls.Tree;

  import mx.events.ListEvent;



  private var dpx:XML = <nav>

   <node label="INBOX">

            <node label="Flora by Gucci" url="assets/swf/movies/flora.swf" />

            <node label="Gucci by Gucci" url="assets/swf/movies/gucci.swf" />

    </node>

   <node label="SENT">

         <node label="Pour Homme" url="assets/swf/movies/ph.swf" />

   </node>


  </nav>

  private var dp:XMLListCollection = new XMLListCollection(dpx.children
());

  private function treeItemClick(e:ListEvent):void

  {

               var item:Object = Tree(e.currentTarget).selectedItem;

               /*

                Open/close the selected item if a branch

               */

               if (tree.dataDescriptor.isBranch(item))

               {

                   tree.expandItem(item,!tree.isItemOpen
(item),false,true);

               }

               else

               {

                // Clicked on an item -- DO STUFF!

               }

           }

           /*

            Function for accessing the Root item of the Tree

           */

           private function getRoot(childObj:Object):Object

           {

            var parentObj:Object = tree.getParentItem(childObj);

            if(parentObj != null) return getRoot(parentObj);

            else return childObj;

           }

           /*

            Close the branch if the open item is not in it

           */

           private function closeOpenItems(e:TreeEvent):void

           {

            var item:Object = e.item;

            for each(var i:Object in tree.openItems)

               {

                if(XML(getRoot(i))....@label != XML(getRoot
(item))....@label)

                {

                 if(i!=item) tree.expandItem(i,false);

                }

               }

           }

 ]]>

 </mx:Script>

 <mx:Tree id="tree"

  width="200"

  height="300"

  dataProvider="{dp}"

  labelField="@label"

  itemClick="treeItemClick(event)"

  itemOpen="closeOpenItems(event)"
  />

</mx:WindowedApplication>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to flex_india@googlegroups.com
To unsubscribe from this group, send email to 
flex_india+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to