<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Adding A ContextMenu To A Flex Tree</title>
	<atom:link href="http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/</link>
	<description>Web Application Design &#38; Development</description>
	<lastBuildDate>Thu, 09 Sep 2010 19:09:18 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1184</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Sat, 07 Nov 2009 14:07:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1184</guid>
		<description>Hi Javier,

I think i got it working.. runnign some tests

contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, database_contextMenuHandler);

Thanks for all the help. Keep you posted</description>
		<content:encoded><![CDATA[<p>Hi Javier,</p>
<p>I think i got it working.. runnign some tests</p>
<p>contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, database_contextMenuHandler);</p>
<p>Thanks for all the help. Keep you posted</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1183</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Sat, 07 Nov 2009 13:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1183</guid>
		<description>Hi, 

I meant  MouseEvent.CONTEXT_MENU is available ONLY  in AIR</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I meant  MouseEvent.CONTEXT_MENU is available ONLY  in AIR</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1182</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Sat, 07 Nov 2009 13:37:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1182</guid>
		<description>Hi, 
Thanks for the response. 
You meant, that i should add this to context menu ?

addEventListener(MouseEvent.CONTEXT_MENU, database_contextMenuHandler);

Also the there is no event MouseEvent.CONTEXT_MENU is available in AIR. I am using flex for web applications ( so it runs in flash player). I tried with MouseEvent.CLICK, but it did not help.

One thing i observed from the begining is when i right click the context menu appears, when i select on the options in the menu, the tree item below is getting highlighted/selected. 

Please let me know. Thank you</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thanks for the response.<br />
You meant, that i should add this to context menu ?</p>
<p>addEventListener(MouseEvent.CONTEXT_MENU, database_contextMenuHandler);</p>
<p>Also the there is no event MouseEvent.CONTEXT_MENU is available in AIR. I am using flex for web applications ( so it runs in flash player). I tried with MouseEvent.CLICK, but it did not help.</p>
<p>One thing i observed from the begining is when i right click the context menu appears, when i select on the options in the menu, the tree item below is getting highlighted/selected. </p>
<p>Please let me know. Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javier Julio</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1181</link>
		<dc:creator>Javier Julio</dc:creator>
		<pubDate>Fri, 06 Nov 2009 21:45:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1181</guid>
		<description>You can have the event handler do whatever you like. The example was merely to demonstrate how to add a context menu to a Tree but since you have the event listener there you can have the handler do anything. I see now that on an earlier comment I posted about selection:

Define the following in the constructor:

addEventListener(MouseEvent.CONTEXT_MENU, database_contextMenuHandler);

And then define the event handler function where the myData variable would be the object in Tree&#039;s dataProvider that you want selected.

private function database_contextMenuHandler(event:MouseEvent):void {
	var tree:Tree = this.owner as Tree;
	tree.selectedItem = myData;
	trace(”new selected item!\n” + tree.selectedItem);
}</description>
		<content:encoded><![CDATA[<p>You can have the event handler do whatever you like. The example was merely to demonstrate how to add a context menu to a Tree but since you have the event listener there you can have the handler do anything. I see now that on an earlier comment I posted about selection:</p>
<p>Define the following in the constructor:</p>
<p>addEventListener(MouseEvent.CONTEXT_MENU, database_contextMenuHandler);</p>
<p>And then define the event handler function where the myData variable would be the object in Tree&#8217;s dataProvider that you want selected.</p>
<p>private function database_contextMenuHandler(event:MouseEvent):void {<br />
	var tree:Tree = this.owner as Tree;<br />
	tree.selectedItem = myData;<br />
	trace(”new selected item!\n” + tree.selectedItem);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1180</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Fri, 06 Nov 2009 21:38:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1180</guid>
		<description>Javier,

Thanks for the response.  I tried the with sample and added the contextmenu  creation in the constructor, but still could not get working, my bad. 

I am not clear if this  line below is only adding event handler ?

edit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, databases_menuItemSelectHandler); 

does the event handler function (databases_menuItemSelectHandler)  should have some extra logic to select /highlight the item in the tree ?

As per your blog, it seems it does not require, Please throw some light. Thanks for all the help

Below is the sample i have been trying
[code]



    
        &lt;![CDATA[
            import mx.events.ListEvent;
             import mx.collections.XMLListCollection;
            [Bindable]
            public var treeMenu:ContextMenu = new ContextMenu();
            public var lastTreeItem:ListEvent;
 
           [Bindable]
            private var company:XML =
              
                
                    

                    
                
                

                    
                    
                                    
                

                    
                    
                                                
              ;
            
            [Bindable]

            private var companyData:XMLListCollection = new XMLListCollection(company.department);
          
        ]]&gt;
    

    
      
  

[/code]

[code]
package views.renderers
{
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	import mx.collections.*;
	import mx.controls.Tree;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.controls.treeClasses.*;
	
	import views.controls.ModelGrid;
	
	public class ModelVersionNode extends TreeItemRenderer
	{
		public var isVersion:Boolean = false;
		public var isPublished:Boolean = false;
		protected var nodeGrid:ModelGrid;
		protected var _tree:Tree;
		
		public function ModelVersionNode()
		{
			super();
			var contextMenu:ContextMenu = new ContextMenu();   
			contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, databases_menuItemSelectHandler);
			var menuItems:Array = [];   
			var edit:ContextMenuItem = new ContextMenuItem(&quot;Edit Name&quot;);   
			edit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, cm_menuItemSelectHandler);   
			menuItems.push(edit);   
			contextMenu.customItems = menuItems;   
			
			this.contextMenu = contextMenu; 
		}
		 override public function set data(value:Object):void
        {
            if(value != null)
            { 
                super.data = value;
                if(TreeListData(super.listData).hasChildren)
                {
                    setStyle(&quot;color&quot;, 0x660099);
                    setStyle(&quot;fontWeight&quot;, &#039;bold&#039;);
		}
		else
		{
		    setStyle(&quot;color&quot;, 0x000000);
		    setStyle(&quot;fontWeight&quot;, &#039;normal&#039;);
		}
            }
         }	 

         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
	   {
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                if(super.data)
                 {
                    if(TreeListData(super.listData).hasChildren)
                    {
                         var tmp:XMLList = new XMLList(TreeListData(super.listData).item);
                         var myStr:int = tmp[0].children().length();
                         super.label.text =  TreeListData(super.listData).label + &quot;(&quot; + myStr + &quot; objects)&quot;;
                    }
                }
            }
		
		

private function databases_menuItemSelectHandler(event:ContextMenuEvent):void {   
			var rowNum:int;
			 if (event.mouseTarget is IListItemRenderer) {
            		rowNum = this._tree.itemRendererToIndex(event.mouseTarget as IListItemRenderer);
            		if (rowNum &gt;= 0) this._tree.selectedIndex = rowNum;
            	}
		}
		
		private function cm_menuItemSelectHandler(event:ContextMenuEvent):void
		{
			
		}
		
     
	}
}

[/code]</description>
		<content:encoded><![CDATA[<p>Javier,</p>
<p>Thanks for the response.  I tried the with sample and added the contextmenu  creation in the constructor, but still could not get working, my bad. </p>
<p>I am not clear if this  line below is only adding event handler ?</p>
<p>edit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, databases_menuItemSelectHandler); </p>
<p>does the event handler function (databases_menuItemSelectHandler)  should have some extra logic to select /highlight the item in the tree ?</p>
<p>As per your blog, it seems it does not require, Please throw some light. Thanks for all the help</p>
<p>Below is the sample i have been trying<br />
[code]</p>
<p>        &lt;![CDATA[<br />
            import mx.events.ListEvent;<br />
             import mx.collections.XMLListCollection;<br />
            [Bindable]<br />
            public var treeMenu:ContextMenu = new ContextMenu();<br />
            public var lastTreeItem:ListEvent;</p>
<p>           [Bindable]<br />
            private var company:XML =</p>
<p>              ;</p>
<p>            [Bindable]</p>
<p>            private var companyData:XMLListCollection = new XMLListCollection(company.department);</p>
<p>        ]]&gt;</p>
<p>[/code]</p>
<p>[code]<br />
package views.renderers<br />
{<br />
	import flash.events.ContextMenuEvent;<br />
	import flash.ui.ContextMenu;<br />
	import flash.ui.ContextMenuItem;</p>
<p>	import mx.collections.*;<br />
	import mx.controls.Tree;<br />
	import mx.controls.listClasses.IListItemRenderer;<br />
	import mx.controls.treeClasses.*;</p>
<p>	import views.controls.ModelGrid;</p>
<p>	public class ModelVersionNode extends TreeItemRenderer<br />
	{<br />
		public var isVersion:Boolean = false;<br />
		public var isPublished:Boolean = false;<br />
		protected var nodeGrid:ModelGrid;<br />
		protected var _tree:Tree;</p>
<p>		public function ModelVersionNode()<br />
		{<br />
			super();<br />
			var contextMenu:ContextMenu = new ContextMenu();<br />
			contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, databases_menuItemSelectHandler);<br />
			var menuItems:Array = [];<br />
			var edit:ContextMenuItem = new ContextMenuItem("Edit Name");<br />
			edit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, cm_menuItemSelectHandler);<br />
			menuItems.push(edit);<br />
			contextMenu.customItems = menuItems;   </p>
<p>			this.contextMenu = contextMenu;<br />
		}<br />
		 override public function set data(value:Object):void<br />
        {<br />
            if(value != null)<br />
            {<br />
                super.data = value;<br />
                if(TreeListData(super.listData).hasChildren)<br />
                {<br />
                    setStyle("color", 0x660099);<br />
                    setStyle("fontWeight", 'bold');<br />
		}<br />
		else<br />
		{<br />
		    setStyle("color", 0x000000);<br />
		    setStyle("fontWeight", 'normal');<br />
		}<br />
            }<br />
         }	 </p>
<p>         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void<br />
	   {<br />
                super.updateDisplayList(unscaledWidth, unscaledHeight);<br />
                if(super.data)<br />
                 {<br />
                    if(TreeListData(super.listData).hasChildren)<br />
                    {<br />
                         var tmp:XMLList = new XMLList(TreeListData(super.listData).item);<br />
                         var myStr:int = tmp[0].children().length();<br />
                         super.label.text =  TreeListData(super.listData).label + "(" + myStr + " objects)";<br />
                    }<br />
                }<br />
            }</p>
<p>private function databases_menuItemSelectHandler(event:ContextMenuEvent):void {<br />
			var rowNum:int;<br />
			 if (event.mouseTarget is IListItemRenderer) {<br />
            		rowNum = this._tree.itemRendererToIndex(event.mouseTarget as IListItemRenderer);<br />
            		if (rowNum &gt;= 0) this._tree.selectedIndex = rowNum;<br />
            	}<br />
		}</p>
<p>		private function cm_menuItemSelectHandler(event:ContextMenuEvent):void<br />
		{</p>
<p>		}</p>
<p>	}<br />
}</p>
<p>[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javier Julio</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1179</link>
		<dc:creator>Javier Julio</dc:creator>
		<pubDate>Fri, 06 Nov 2009 19:56:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1179</guid>
		<description>@Kumar 

The Flex cookbook sample I refer too I have linked within the article. You can find it here:

http://cookbooks.adobe.com/index.cfm?event=showdetails&amp;postId=62

I used the renderer there as a starting point because an item renderer for a Tree is very different from a List which we are much more accustomed to working with. My mistake was thinking I could just drop in any renderer but it doesn&#039;t work that way as it will mess up the Tree itself, missing arrow icons, etc. The cookbook sample is what I started off with.</description>
		<content:encoded><![CDATA[<p>@Kumar </p>
<p>The Flex cookbook sample I refer too I have linked within the article. You can find it here:</p>
<p><a href="http://cookbooks.adobe.com/index.cfm?event=showdetails&amp;postId=62" rel="nofollow">http://cookbooks.adobe.com/index.cfm?event=showdetails&amp;postId=62</a></p>
<p>I used the renderer there as a starting point because an item renderer for a Tree is very different from a List which we are much more accustomed to working with. My mistake was thinking I could just drop in any renderer but it doesn&#8217;t work that way as it will mess up the Tree itself, missing arrow icons, etc. The cookbook sample is what I started off with.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1177</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Fri, 06 Nov 2009 19:37:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1177</guid>
		<description>Sorry for the typos but selection of tree item is not happening</description>
		<content:encoded><![CDATA[<p>Sorry for the typos but selection of tree item is not happening</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1176</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Fri, 06 Nov 2009 19:37:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1176</guid>
		<description>Hi, 

I have read the entire post. I tired what Javier Hulio said, but selecting of Tree item is NOT being selected. 

When you say flex  cookbook sample, are you referring to &quot; Create an Item Renderer for a Tree&quot;, page 142 sample code.

Please help

Thanks</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I have read the entire post. I tired what Javier Hulio said, but selecting of Tree item is NOT being selected. </p>
<p>When you say flex  cookbook sample, are you referring to &#8221; Create an Item Renderer for a Tree&#8221;, page 142 sample code.</p>
<p>Please help</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ktdsm</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1170</link>
		<dc:creator>ktdsm</dc:creator>
		<pubDate>Sat, 31 Oct 2009 01:38:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-1170</guid>
		<description>hi, i need some help ...    I have a flex screen . It has a datagrid and a tree control.I  want to  create one context menu for datgrid with COPY  option and the other context menu for tree with PASTE. 
I want to copy the row from datagrid to tree through copy . paste menu options.
I have created two seperate contextmenus for each control. I dont know exactly how would i retain the copied values from datagrid , when COPY option is clicked on the contextmenu and then paste it to the tree control. 
I am a beginner and having a hard time in getting  the functionality  implemented.

Please help me out...</description>
		<content:encoded><![CDATA[<p>hi, i need some help &#8230;    I have a flex screen . It has a datagrid and a tree control.I  want to  create one context menu for datgrid with COPY  option and the other context menu for tree with PASTE.<br />
I want to copy the row from datagrid to tree through copy . paste menu options.<br />
I have created two seperate contextmenus for each control. I dont know exactly how would i retain the copied values from datagrid , when COPY option is clicked on the contextmenu and then paste it to the tree control.<br />
I am a beginner and having a hard time in getting  the functionality  implemented.</p>
<p>Please help me out&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javier Julio</title>
		<link>http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-592</link>
		<dc:creator>Javier Julio</dc:creator>
		<pubDate>Sat, 06 Jun 2009 20:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.daniell.acr90-dev-02/2008/04/21/adding-a-contextmenu-to-a-flex-tree/#comment-592</guid>
		<description>@Arun,
What you need to do is create a variable (you can make it bindable) and bind the visible property of that canvas. So initially that variable will be set to false because by default you don&#039;t want it displayed. Then when you click on an item in the tree you set that bindable variable to true and your canvas will appear.</description>
		<content:encoded><![CDATA[<p>@Arun,<br />
What you need to do is create a variable (you can make it bindable) and bind the visible property of that canvas. So initially that variable will be set to false because by default you don&#8217;t want it displayed. Then when you click on an item in the tree you set that bindable variable to true and your canvas will appear.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
