<?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: Update: Solution to disappearing data in your itemRenderer</title>
	<atom:link href="http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/</link>
	<description>The Dead Tree Blog</description>
	<lastBuildDate>Wed, 18 Jan 2012 08:30:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Patrick</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-57653</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Wed, 09 Nov 2011 21:30:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-57653</guid>
		<description>Don&#039;t usually post these but when my ADG content started disappearing, I was afraid it was going to be a battle...  VariableRowHeight wins!!!</description>
		<content:encoded><![CDATA[<p>Don&#8217;t usually post these but when my ADG content started disappearing, I was afraid it was going to be a battle&#8230;  VariableRowHeight wins!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-53814</link>
		<dc:creator>Cory</dc:creator>
		<pubDate>Thu, 20 Oct 2011 15:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-53814</guid>
		<description>Kalen - if what you are saying is correct, then if I override my &quot;set data&quot; field in my itemRenderer and call invalidateProperties(), and then explicitly reset all of my data in the itemrenderer, this issue wouldn&#039;t happen.  But it still does.  This has to be a bug in flex, does it not?</description>
		<content:encoded><![CDATA[<p>Kalen &#8211; if what you are saying is correct, then if I override my &#8220;set data&#8221; field in my itemRenderer and call invalidateProperties(), and then explicitly reset all of my data in the itemrenderer, this issue wouldn&#8217;t happen.  But it still does.  This has to be a bug in flex, does it not?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-53813</link>
		<dc:creator>Cory</dc:creator>
		<pubDate>Thu, 20 Oct 2011 15:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-53813</guid>
		<description>&quot;selectable = false&quot; on the  that is.</description>
		<content:encoded><![CDATA[<p>&#8220;selectable = false&#8221; on the  that is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-53811</link>
		<dc:creator>Cory</dc:creator>
		<pubDate>Thu, 20 Oct 2011 15:32:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-53811</guid>
		<description>&quot;selectable = false&quot; fixes this too</description>
		<content:encoded><![CDATA[<p>&#8220;selectable = false&#8221; fixes this too</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kalen Gibbons</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-47852</link>
		<dc:creator>Kalen Gibbons</dc:creator>
		<pubDate>Wed, 21 Sep 2011 20:05:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-47852</guid>
		<description>Hi FlexBoz,
  This is a very common problem.  The problem is that itemRenderers in Lists are recycled, meaning that Flex does not create a instance of the itemRenderer for every object in your data. Instead it only creates enough for what is visible in the list at one time.  These itemRenderers are then reused when a user scrolls down the list and the data is just swapped out.  For a full explanation check out this article: http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html.

So... because the itemRenderers are re-used you can&#039;t store instance data in them, like the state of a checkbox.  Instead you need to store that information somewhere outside the renderer, typically in the data that&#039;s being passed into the renderer.  You can simply add a property to the data that will store whether the checkbox has been checked or not and then override the set data function in the itemRenderer. In the set data function you can look at the data, and manually check or uncheck that checkbox.  The same article above expands on this concept a bit in the second part of the article.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt2.html</description>
		<content:encoded><![CDATA[<p>Hi FlexBoz,<br />
  This is a very common problem.  The problem is that itemRenderers in Lists are recycled, meaning that Flex does not create a instance of the itemRenderer for every object in your data. Instead it only creates enough for what is visible in the list at one time.  These itemRenderers are then reused when a user scrolls down the list and the data is just swapped out.  For a full explanation check out this article: <a href="http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html" rel="nofollow">http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html</a>.</p>
<p>So&#8230; because the itemRenderers are re-used you can&#8217;t store instance data in them, like the state of a checkbox.  Instead you need to store that information somewhere outside the renderer, typically in the data that&#8217;s being passed into the renderer.  You can simply add a property to the data that will store whether the checkbox has been checked or not and then override the set data function in the itemRenderer. In the set data function you can look at the data, and manually check or uncheck that checkbox.  The same article above expands on this concept a bit in the second part of the article.<br />
<a href="http://www.adobe.com/devnet/flex/articles/itemrenderers_pt2.html" rel="nofollow">http://www.adobe.com/devnet/flex/articles/itemrenderers_pt2.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FlexBoz</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-47708</link>
		<dc:creator>FlexBoz</dc:creator>
		<pubDate>Wed, 21 Sep 2011 05:03:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-47708</guid>
		<description>Hello Kalen,

I have having problems with checkboxes in my itemrenderer being checked/unchecked when scrolling in my datagrid. Grateful if you could have a look.


My Flex application is as such:



	
	
		
	
	
	
		
	
	
	
		
		
		
		
		&lt;!--
			
			
			
			
			
			
			
			
			
			
			
		
		--&gt;
	
	
	
	
		
								
				
					
						
							
								
							
						
					
					
				
					
						
							
								
								
									
								
								
								
							
						
					
				
				
			
		
	
		





And my XML file is as such:





	
	
	
	
	
	
	
	




Bet I am missing something in the code, but dont know what. Pls help</description>
		<content:encoded><![CDATA[<p>Hello Kalen,</p>
<p>I have having problems with checkboxes in my itemrenderer being checked/unchecked when scrolling in my datagrid. Grateful if you could have a look.</p>
<p>My Flex application is as such:</p>
<p>		&lt;!&#8211;</p>
<p>		&#8211;&gt;</p>
<p>And my XML file is as such:</p>
<p>Bet I am missing something in the code, but dont know what. Pls help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-4638</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Mon, 14 Dec 2009 23:26:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-4638</guid>
		<description>This didn&#039;t work for me in my ActionScript class, but I came up with something similar that did the trick.

&lt;CODE&gt;
override public function set data(value:Object):void
{
	super.data = value;
	validateNow();
}
&lt;/CODE&gt;

I&#039;m not sure what the difference is between calling validateNow this way versus calling it in the data change event listener, but this worked for me while the event listener method didn&#039;t.</description>
		<content:encoded><![CDATA[<p>This didn&#8217;t work for me in my ActionScript class, but I came up with something similar that did the trick.</p>
<p><code><br />
override public function set data(value:Object):void<br />
{<br />
	super.data = value;<br />
	validateNow();<br />
}<br />
</code></p>
<p>I&#8217;m not sure what the difference is between calling validateNow this way versus calling it in the data change event listener, but this worked for me while the event listener method didn&#8217;t.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timjowers</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-4373</link>
		<dc:creator>timjowers</dc:creator>
		<pubDate>Fri, 13 Nov 2009 16:44:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-4373</guid>
		<description>No luck here yet. I used Flexnaut&#039;s code for custom item renderers in a tree or list: http://flexnaut.blogspot.com/2009/10/extensible-list-item-renderers.html. Then I tried to vary the item renders. It works fine on the first expansion. It works fine as long as no scrolling occurs. Once scrolling occurs, then the nodes jump around and their layout is lost as well as the height of their node in the tree. That is, one node type is a datagrid and the other is the node type in Flexnaut&#039;s example: an ActorRenderer. Here&#039;s the custom item renderer with the two node types. These are selected against in the creationComplete method (as there the &quot;data&quot; can be checked and used to select the node type.)



  
    
  
  
  	
	  	
	  	
  	
  


So much for using differing ItemRenderers in the same tree. I guess I&#039;ll play with show/hide, states, or height=0 techniques.</description>
		<content:encoded><![CDATA[<p>No luck here yet. I used Flexnaut&#8217;s code for custom item renderers in a tree or list: <a href="http://flexnaut.blogspot.com/2009/10/extensible-list-item-renderers.html" rel="nofollow">http://flexnaut.blogspot.com/2009/10/extensible-list-item-renderers.html</a>. Then I tried to vary the item renders. It works fine on the first expansion. It works fine as long as no scrolling occurs. Once scrolling occurs, then the nodes jump around and their layout is lost as well as the height of their node in the tree. That is, one node type is a datagrid and the other is the node type in Flexnaut&#8217;s example: an ActorRenderer. Here&#8217;s the custom item renderer with the two node types. These are selected against in the creationComplete method (as there the &#8220;data&#8221; can be checked and used to select the node type.)</p>
<p>So much for using differing ItemRenderers in the same tree. I guess I&#8217;ll play with show/hide, states, or height=0 techniques.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BethL</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-3990</link>
		<dc:creator>BethL</dc:creator>
		<pubDate>Wed, 14 Oct 2009 17:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-3990</guid>
		<description>Thank You for this simple solution!  I&#039;ve been racking my brain for 3 hours now on why my radio buttons kept losing the data when scrolling down.  I tried lots of painful things and it was as simple as using validateNow() in the datagrid!
Thank You!!!</description>
		<content:encoded><![CDATA[<p>Thank You for this simple solution!  I&#8217;ve been racking my brain for 3 hours now on why my radio buttons kept losing the data when scrolling down.  I tried lots of painful things and it was as simple as using validateNow() in the datagrid!<br />
Thank You!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jose miguel</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/12/update-solution-to-disappearing-data-in-your-itemrenderer2/comment-page-1/#comment-3725</link>
		<dc:creator>jose miguel</dc:creator>
		<pubDate>Thu, 17 Sep 2009 22:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=125#comment-3725</guid>
		<description>hi, i have tried this solution in a custom item Renderer (extended from TreeItemRenderer), but i cannot get it to work:

public class BaseTreeItemRenderer extends TreeItemRenderer {
		
    	private var itemIcon:Image;
    	private var legendIcon:Image;
		
		public function BaseTreeItemRenderer() {
			super();
		
			itemIcon = new Image();
			itemIcon.width = 16;
			itemIcon.height = 16;
			itemIcon.scaleContent = true;
			itemIcon.visible = false;
			
			legendIcon = new Image();
			legendIcon.width = 25;
			legendIcon.height = 25;
			legendIcon.scaleContent = true;
			legendIcon.visible = false;
			
			this.addEventListener(FlexEvent.DATA_CHANGE, dataChangeHandler);
		}
		
		private function dataChangeHandler(event:FlexEvent):void {
			validateNow();
		}
		
		override protected function commitProperties( ): void {
			super.commitProperties( );
			if ((data != null) &amp;&amp; (data is TreeNode)) {
				var node:TreeNode = data as TreeNode;
				getControl().selected = node.selected;
			}
		}
		
		override protected function measure():void {
			super.measure();
			var w:Number = data ? (data as BaseNode).indent : 0;
	
			if ( disclosureIcon )
				w += disclosureIcon.width;
	
			if ( icon )
				w += icon.measuredWidth;
	
			if ( label.width &lt; 4 &#124;&#124; label.height  measuredHeight )
					measuredHeight = icon.measuredHeight;
			}
		}
		
		override protected function createChildren(): void	{
			super.createChildren();
			addChild(itemIcon);
			addChild(legendIcon);
		}
		
		override protected function updateDisplayList( unscaledWidth: Number, unscaledHeight: Number ): void {
			super.updateDisplayList( unscaledWidth, unscaledHeight );
			var node:TreeNode = data as TreeNode;
			var startx:Number = data ? (data as BaseNode).indent : 0;
			var xIncrement:Number = 3;
			
			if ( disclosureIcon ) {
				disclosureIcon.x = startx;
				startx = disclosureIcon.x + disclosureIcon.width;
				disclosureIcon.setActualSize( disclosureIcon.width, disclosureIcon.height );
			}
			
			var labelFormat:TextFormat = new TextFormat();
			
			if ( icon ) {
				if ((node) &amp;&amp; (node.level == 2)) {
					icon.visible = false;
					legendIcon.visible = false;
					
					labelFormat.italic = true;
					label.setTextFormat(labelFormat);
					
					itemIcon.source = (data as BaseNode).iconSource;
					itemIcon.visible = true;
					itemIcon.x = startx + xIncrement;
					startx = itemIcon.x + itemIcon.width;
				} else if (data is LegendNode) {
					 icon.visible = false;
					 itemIcon.visible = false;
					 
					legendIcon.source = (data as BaseNode).iconSource;
					legendIcon.visible = true;
					legendIcon.visible = true;
					legendIcon.x = startx + xIncrement;
					startx = legendIcon.x + legendIcon.width;
				} else {
					labelFormat.bold = true;
					labelFormat.size = 11;
					label.setTextFormat(labelFormat);
					
					itemIcon.visible = false;
					legendIcon.visible = false;
					icon.x = startx + xIncrement;
					startx = icon.x + icon.measuredWidth;
					icon.setActualSize(icon.measuredWidth, icon.measuredHeight);
				}
			}
			
			if (getControl()) {
				if ((node) &amp;&amp; (node.level == 2)) {
					getControl().x = startx + xIncrement;
					startx = getControl().x + getControl().measuredWidth;
					getControl().setActualSize(getControl().measuredWidth, getControl().measuredHeight);
				} else {
					getControl().visible = false;
				}
			}
			label.x = startx + xIncrement;
			label.setActualSize(unscaledWidth - startx, measuredHeight );
		}
		
		protected function getControl():Button { // this is overriden by some renderers wich also inherit from this one
			return null;
		}
		
	}
this item renderer creates a check or radio button next to the label of the item; the class that inherit from this one pass the created checkbox or radio button via the getControl method

as you see, i have placed your solution in the dataChangeHandler but is not working; if i scroll the tree the checkbox or radio button still disappears</description>
		<content:encoded><![CDATA[<p>hi, i have tried this solution in a custom item Renderer (extended from TreeItemRenderer), but i cannot get it to work:</p>
<p>public class BaseTreeItemRenderer extends TreeItemRenderer {</p>
<p>    	private var itemIcon:Image;<br />
    	private var legendIcon:Image;</p>
<p>		public function BaseTreeItemRenderer() {<br />
			super();</p>
<p>			itemIcon = new Image();<br />
			itemIcon.width = 16;<br />
			itemIcon.height = 16;<br />
			itemIcon.scaleContent = true;<br />
			itemIcon.visible = false;</p>
<p>			legendIcon = new Image();<br />
			legendIcon.width = 25;<br />
			legendIcon.height = 25;<br />
			legendIcon.scaleContent = true;<br />
			legendIcon.visible = false;</p>
<p>			this.addEventListener(FlexEvent.DATA_CHANGE, dataChangeHandler);<br />
		}</p>
<p>		private function dataChangeHandler(event:FlexEvent):void {<br />
			validateNow();<br />
		}</p>
<p>		override protected function commitProperties( ): void {<br />
			super.commitProperties( );<br />
			if ((data != null) &amp;&amp; (data is TreeNode)) {<br />
				var node:TreeNode = data as TreeNode;<br />
				getControl().selected = node.selected;<br />
			}<br />
		}</p>
<p>		override protected function measure():void {<br />
			super.measure();<br />
			var w:Number = data ? (data as BaseNode).indent : 0;</p>
<p>			if ( disclosureIcon )<br />
				w += disclosureIcon.width;</p>
<p>			if ( icon )<br />
				w += icon.measuredWidth;</p>
<p>			if ( label.width &lt; 4 || label.height  measuredHeight )<br />
					measuredHeight = icon.measuredHeight;<br />
			}<br />
		}</p>
<p>		override protected function createChildren(): void	{<br />
			super.createChildren();<br />
			addChild(itemIcon);<br />
			addChild(legendIcon);<br />
		}</p>
<p>		override protected function updateDisplayList( unscaledWidth: Number, unscaledHeight: Number ): void {<br />
			super.updateDisplayList( unscaledWidth, unscaledHeight );<br />
			var node:TreeNode = data as TreeNode;<br />
			var startx:Number = data ? (data as BaseNode).indent : 0;<br />
			var xIncrement:Number = 3;</p>
<p>			if ( disclosureIcon ) {<br />
				disclosureIcon.x = startx;<br />
				startx = disclosureIcon.x + disclosureIcon.width;<br />
				disclosureIcon.setActualSize( disclosureIcon.width, disclosureIcon.height );<br />
			}</p>
<p>			var labelFormat:TextFormat = new TextFormat();</p>
<p>			if ( icon ) {<br />
				if ((node) &amp;&amp; (node.level == 2)) {<br />
					icon.visible = false;<br />
					legendIcon.visible = false;</p>
<p>					labelFormat.italic = true;<br />
					label.setTextFormat(labelFormat);</p>
<p>					itemIcon.source = (data as BaseNode).iconSource;<br />
					itemIcon.visible = true;<br />
					itemIcon.x = startx + xIncrement;<br />
					startx = itemIcon.x + itemIcon.width;<br />
				} else if (data is LegendNode) {<br />
					 icon.visible = false;<br />
					 itemIcon.visible = false;</p>
<p>					legendIcon.source = (data as BaseNode).iconSource;<br />
					legendIcon.visible = true;<br />
					legendIcon.visible = true;<br />
					legendIcon.x = startx + xIncrement;<br />
					startx = legendIcon.x + legendIcon.width;<br />
				} else {<br />
					labelFormat.bold = true;<br />
					labelFormat.size = 11;<br />
					label.setTextFormat(labelFormat);</p>
<p>					itemIcon.visible = false;<br />
					legendIcon.visible = false;<br />
					icon.x = startx + xIncrement;<br />
					startx = icon.x + icon.measuredWidth;<br />
					icon.setActualSize(icon.measuredWidth, icon.measuredHeight);<br />
				}<br />
			}</p>
<p>			if (getControl()) {<br />
				if ((node) &amp;&amp; (node.level == 2)) {<br />
					getControl().x = startx + xIncrement;<br />
					startx = getControl().x + getControl().measuredWidth;<br />
					getControl().setActualSize(getControl().measuredWidth, getControl().measuredHeight);<br />
				} else {<br />
					getControl().visible = false;<br />
				}<br />
			}<br />
			label.x = startx + xIncrement;<br />
			label.setActualSize(unscaledWidth &#8211; startx, measuredHeight );<br />
		}</p>
<p>		protected function getControl():Button { // this is overriden by some renderers wich also inherit from this one<br />
			return null;<br />
		}</p>
<p>	}<br />
this item renderer creates a check or radio button next to the label of the item; the class that inherit from this one pass the created checkbox or radio button via the getControl method</p>
<p>as you see, i have placed your solution in the dataChangeHandler but is not working; if i scroll the tree the checkbox or radio button still disappears</p>
]]></content:encoded>
	</item>
</channel>
</rss>

