<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Randy Troppmann &#187; as3</title>
	<atom:link href="http://www.randytroppmann.com/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randytroppmann.com</link>
	<description>Flash • Flex • iPhone • Android: software development and visual communication design</description>
	<lastBuildDate>Fri, 23 Jul 2010 15:38:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sorting XMLListCollection and case sensitivity</title>
		<link>http://www.randytroppmann.com/2009/02/23/sorting-an-xmllistcollection/</link>
		<comments>http://www.randytroppmann.com/2009/02/23/sorting-an-xmllistcollection/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 18:51:48 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[Flex development]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://www.randytroppmann.com/?p=265</guid>
		<description><![CDATA[Consider this xml: PLAIN TEXT Actionscript: var myImageXML:XML = &#160; &#160; &#60;image&#62; &#160; &#160; &#160; &#160; &#60;term text="New Term 498"/&#62; &#160; &#160; &#160; &#160; &#60;term text="a new term 550"/&#62; &#160; &#160; &#160; &#160; &#60;term text="a new term"/&#62; &#160; &#160; &#160; &#160; &#60;term text="New Term 668"/&#62; &#160; &#160; &#160;&#60;/image&#62; You can create an xmlListCollection and then [...]]]></description>
			<content:encoded><![CDATA[<p>Consider this xml:</p>
<div class="igBar"><span id="lactionscript-4"><a href="#" onclick="javascript:showCodeTxt('actionscript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-4">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> myImageXML:<span style="color: #0066CC;">XML</span> = </div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;image&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;term <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">"New Term 498"</span>/&gt;</div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;term <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">"a new term 550"</span>/&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;term <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">"a new term"</span>/&gt;</div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;term <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">"New Term 668"</span>/&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;&lt;/image&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You can create an xmlListCollection and then sort the collection based on the term text.</p>
<div class="igBar"><span id="lactionscript-5"><a href="#" onclick="javascript:showCodeTxt('actionscript-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-5">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">SortField</span>;</div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #0066CC;">Sort</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> terms:XMLListCollection = <span style="color: #000000; font-weight: bold;">new</span> XMLListCollection<span style="color: #66cc66;">&#40;</span>myImageXML..<span style="color: #006600;">term</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">sort</span>:<span style="color: #0066CC;">Sort</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sort</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> sortField:SortField = <span style="color: #000000; font-weight: bold;">new</span> SortField<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"@text"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">sort</span>.<span style="color: #006600;">fields</span> = <span style="color: #66cc66;">&#91;</span>sortField<span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:IG_LINE_COLOUR_2;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">terms.<span style="color: #0066CC;">sort</span> = <span style="color: #0066CC;">sort</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">terms.<span style="color: #006600;">refresh</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>What threw me for a loop was the sort result (by term text value):</p>
<p>New Term 498<br />
New Term 668<br />
a new term<br />
a new term 550</p>
<p>As it turns out the default value for the sort case insensitivity is false. To solve this, set the property in the SortField object:</p>
<div class="igBar"><span id="lactionscript-6"><a href="#" onclick="javascript:showCodeTxt('actionscript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-6">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:IG_LINE_COLOUR_1;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sortField.<span style="color: #006600;">caseInsensitive</span> = <span style="color: #000000; font-weight: bold;">true</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>and the sort will happen as expected:</p>
<p>a new term<br />
a new term 550<br />
New Term 498<br />
New Term 668</p>
]]></content:encoded>
			<wfw:commentRss>http://www.randytroppmann.com/2009/02/23/sorting-an-xmllistcollection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
