<?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: ArrayCollection weirdness</title>
	<atom:link href="http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/</link>
	<description>Comments and thoughts on technology from Marc Hughes</description>
	<lastBuildDate>Wed, 14 Jul 2010 19:03:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Slon_vsapogah</title>
		<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/comment-page-1/#comment-865</link>
		<dc:creator>Slon_vsapogah</dc:creator>
		<pubDate>Sun, 07 Jun 2009 20:05:25 +0000</pubDate>
		<guid isPermaLink="false">http://rogue-development.com/blog2/?p=137#comment-865</guid>
		<description>Marc, thank you very much. You&#039;ve helped me a lot!</description>
		<content:encoded><![CDATA[<p>Marc, thank you very much. You&#8217;ve helped me a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JabbyPanda</title>
		<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/comment-page-1/#comment-328</link>
		<dc:creator>JabbyPanda</dc:creator>
		<pubDate>Sat, 07 Jun 2008 10:32:12 +0000</pubDate>
		<guid isPermaLink="false">http://rogue-development.com/blog2/?p=137#comment-328</guid>
		<description>I&#039;ve had figured out my problem with using &#039;getItemIndex&#039; on the collection that is being sorted (has an custom Sort applied). 

Why my problem occured? 

1) I&#039;m changing the value of the object field that is used by SortField (projectInfo.name)
2) as a consequence - the sort order of sorted collection&#039;s items changes 
3) and then &#039;getItemIndex&#039; cannot return correct value, returns -1 instead.

Thus, to conclude: 

After changing the value of the object field that is used by SortField, we MUST call:
  projects.refresh();

to resort the collection to enable &#039;getItemIndex&#039; to return correct value.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve had figured out my problem with using &#8216;getItemIndex&#8217; on the collection that is being sorted (has an custom Sort applied). </p>
<p>Why my problem occured? </p>
<p>1) I&#8217;m changing the value of the object field that is used by SortField (projectInfo.name)<br />
2) as a consequence &#8211; the sort order of sorted collection&#8217;s items changes<br />
3) and then &#8216;getItemIndex&#8217; cannot return correct value, returns -1 instead.</p>
<p>Thus, to conclude: </p>
<p>After changing the value of the object field that is used by SortField, we MUST call:<br />
  projects.refresh();</p>
<p>to resort the collection to enable &#8216;getItemIndex&#8217; to return correct value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JabbyPanda</title>
		<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/comment-page-1/#comment-322</link>
		<dc:creator>JabbyPanda</dc:creator>
		<pubDate>Fri, 06 Jun 2008 14:10:30 +0000</pubDate>
		<guid isPermaLink="false">http://rogue-development.com/blog2/?p=137#comment-322</guid>
		<description>In my case getItemIndex returns -1 when it should not even when simple custom Sort is applied to the collection, without custom compare function, e.g:

var sortProjects : Sort = new Sort();
sortProjects.fields  = [new SortField(&quot;name&quot;, true, false)];
projects.sort = sortProjects;
projects.refresh();

-----------------------
later in the code
-----------------------

var projectInfo : ProjectInfo = projects.getItemAt(1);
projectInfo.name = &quot;New name&quot;;
var index : int = projects.getItemIndex(projectInfo); // returns -1</description>
		<content:encoded><![CDATA[<p>In my case getItemIndex returns -1 when it should not even when simple custom Sort is applied to the collection, without custom compare function, e.g:</p>
<p>var sortProjects : Sort = new Sort();<br />
sortProjects.fields  = [new SortField("name", true, false)];<br />
projects.sort = sortProjects;<br />
projects.refresh();</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
later in the code<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>var projectInfo : ProjectInfo = projects.getItemAt(1);<br />
projectInfo.name = &#8220;New name&#8221;;<br />
var index : int = projects.getItemIndex(projectInfo); // returns -1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/comment-page-1/#comment-198</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Thu, 28 Feb 2008 17:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://rogue-development.com/blog2/?p=137#comment-198</guid>
		<description>The array collection had a custom sort order applied.&lt;br/&gt;&lt;br/&gt;That custom sort has a compare function set.  The compare function didn&#039;t handle the a==b element correctly.&lt;br/&gt;&lt;br/&gt;Now, the ArrayCollection class will use your compare function when you call getItemIndex so it can do a quick binary search instead of a long linear search.&lt;br/&gt;&lt;br/&gt;So using our bad sorting compare function, it never found anything equal, and you got that weirdness.</description>
		<content:encoded><![CDATA[<p>The array collection had a custom sort order applied.</p>
<p>That custom sort has a compare function set.  The compare function didn&#8217;t handle the a==b element correctly.</p>
<p>Now, the ArrayCollection class will use your compare function when you call getItemIndex so it can do a quick binary search instead of a long linear search.</p>
<p>So using our bad sorting compare function, it never found anything equal, and you got that weirdness.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
