1 Reply Latest reply on Dec 15, 2009 11:07 PM by Sophie_cordier

    How to create a customized menu for rightclick on tree item??

    aruvasavi Level 1

      How to create a customized menu for rightclick on tree item??

      Hi

       

       

      If any one worked on how to crete customized menu on right click of tree item, please help me.

      I am able to add menu item to the right click on tree, but I am getting builtinitems also along with right click...

       

      Please find my code.....please help me

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();" viewSourceURL="srcview/index.html">

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.events.ListEvent;

       

      import mx.controls.Alert;

       

      import mx.controls.Menu;

       

      import mx.events.MenuEvent;

      [

      Bindable]

       

      public var treeMenu:ContextMenu = new ContextMenu();

       

      public var lastTreeItem:ListEvent;

       

       

      public function init():void

      {

      treeMenu.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuTriggered);

      treeMenu.hideBuiltInItems();

      }

       

       

      public function contextMenuTriggered(event:ContextMenuEvent):void

      {

      treeMenu.customItems =

      new Array();

       

       

      if( lastTreeItem != null )

      {

       

      if( lastTreeItem.itemRenderer.data.@TargetType == "Parent" ){

       

      var addParentMenuItem:ContextMenuItem = new ContextMenuItem("Add Parent");

      treeMenu.customItems.push(addParentMenuItem);

      }

      else {

       

      var addChildMenuItem:ContextMenuItem = new ContextMenuItem("Add Child");

      treeMenu.customItems.push(addChildMenuItem);

      }

      }

      }

       

       

       

      public function setLastTreeItem(event:ListEvent):void

      {

      lastTreeItem = event;

      }

       

      ]]>

       

      </mx:Script>

       

       

      <mx:Tree id="myTree"

      width="

      100%" height="100%"

      labelField="

      @Name"

      dataProvider="

      {treeData}"

      contextMenu="

      {treeMenu}"

      itemRollOver="setLastTreeItem(event)"

       

      />

       

       

      <mx:XMLListCollection id="treeData" source="{nodes.Node}" />

       

       

      <mx:XML id="nodes">

      <root>

      <Node Name="Parent 1" TargetType="Parent">

      <Node Name="Parent 1 - Child 1" TargetType="Child"/>

      </Node>

      <Node Name="Parent 2" TargetId="3" TargetType="Parent">

      <Node Name="Parent 2 - Child 1" TargetType="Child"/>

      <Node Name="Parent 2 - Child 2" TargetType="Child"/>

      </Node>

      <Node Name="Parent 3" TargetType="Parent">

      <Node Name="Parent 3 - Child 1" TargetType="Child"/>

      <Node Name="Parent 3 - Child 2" TargetType="Child"/>

      <Node Name="Parent 3 - Child 3" TargetType="Child"/>

      </Node>

      </root>

       

      </mx:XML>

       

      </mx:Application>

       

       

       

      Thanks in advance

      Aruna.S.N.