<?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"
	>
<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>
	<pubDate>Wed, 07 Jan 2009 03:19:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: JabbyPanda</title>
		<link>http://www.rogue-development.com/blog2/2008/02/arraycollection-weirdness/#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've had figured out my problem with using 'getItemIndex' on the collection that is being sorted (has an custom Sort applied). 

Why my problem occured? 

1) I'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's items changes 
3) and then 'getItemIndex' 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 'getItemIndex' 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 - 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-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("name", true, false)];
projects.sort = sortProjects;
projects.refresh();

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

var projectInfo : ProjectInfo = projects.getItemAt(1);
projectInfo.name = "New name";
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-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'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>
