Yahoo is getting flakey right now, but here is a correction to my previous 
post, whenever that comes through.  The example is cleaned up and simplified.  
The bugs I was seeing appear to have been the result of setting the "animate" 
argument of expandItem() to true.  Setting that to false seems to have corected 
the bugs.
Tracy

<?xml version="1.0" encoding="utf-8"?>
<!-- Synchronized Trees example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; height="100%">

<mx:Script><![CDATA[
  import mx.events.TreeEvent;
  
  private function onChangeTree1(oEvent:Event):void
  {
    var xmlSelected:XML = XML(tree1.selectedItem);  //get the selected item, 
cast as xml
    tree2.selectedItem = xmlSelected;               //set the tree2 selected 
item 
  }//onChangeTree1
  
  /** TreeEvent gives us access to the dataProvider Item, in this case XML */
  private function onOpenClose(oEvent:TreeEvent, bOpen:Boolean):void
  {
    var xmlNode:XML = XML(oEvent.item);  //cast the tree1 item as xml
    tree2.expandItem(xmlNode,bOpen);      //expand the node on tree2
  }//onOpenClose
     
]]></mx:Script>

  <mx:Panel title="Synchronized Tree Example" height="100%" width="100%" 
      paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
    <mx:HDividedBox width="100%" height="100%">
        <mx:Tree id="tree1" width="50%" height="100%" labelField="@label"
            showRoot="false" dataProvider="{treeData}" 
            change="onChangeTree1(event)" 
            itemOpen="onOpenClose(event, true)"
            itemClose="onOpenClose(event, false)" 
        />
        <mx:Tree id="tree2" width="50%" height="100%" labelField="@label"
            showRoot="false" dataProvider="{treeData}"
        />
    </mx:HDividedBox>
  </mx:Panel>
  
  <mx:XMLList id="treeData">
    <node label="root">
      <node label="Mail Box">
        <node label="Inbox">
          <node label="Marketing"/>
          <node label="Personal"/>
        </node>
        <node label="Outbox">
          <node label="Professional"/>
        </node>
        <node label="Spam"/>
        <node label="Sent"/>
      </node>
      <node label="Saved">
        <node label="Work">
          <node label="Hardware"/>
          <node label="Software"/>
        </node>  
        <node label="Personal">
          <node label="Home"/>
          <node label="Shopping">
            <node label="Christmas"/>
            <node label="Birthday"/>
          </node>
        </node>                   
      </node>   
    </node>
  </mx:XMLList>  
</mx:Application>
________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Harald 
Kucharek
Sent: Wednesday, March 28, 2007 9:42 AM
To: [email protected]
Subject: [flexcoders] Connecting two tree views

Hi,

I'm new to Flex and want the following: I have two Tree views side by side, 
based on the same XML-datasource. When I click one node in the left tree, I 
want  the node holding the same data to be expanded on the right tree.

Naive :-) Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
       pageTitle="Tree Sync">
       
    <mx:Script>
        <![CDATA[
        
        public function treeItemClicked(event:Event):void {
             rightTree.expandItem(leftTree.selectedItem, true);
         }
        
        ]]>
    </mx:Script>
       
    <mx:XML id="dataSet" source="data/tree.xml" xmlns=""/>

    <mx:Panel x="10" y="10" width="465" height="459" layout="absolute">
        <mx:HDividedBox x="10" y="10" height="399" width="425">
            <mx:Tree width="100%" height="100%" 
                id="leftTree"  dataProvider="{dataSet}" 
                showRoot="false" labelField="@label" 
                itemClick="treeItemClicked(event)" ></mx:Tree>
            <mx:Tree width="100%" height="100%" 
                id="rightTree" dataProvider="{dataSet}" 
                showRoot="false" labelField="@label"></mx:Tree>
        </mx:HDividedBox>
    </mx:Panel>
    
</mx:Application>

Of  course, rightTree.expandItem(leftTree.selectedItem, true); isn't working as 
I hoped it may. Is there an easy solution for my task?

Thanks in advance,

Harald

 

Reply via email to