<?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>FlexOOP &#187; dedupeArrayCollection</title>
	<atom:link href="http://flexoop.com/tag/dedupearraycollection/feed/" rel="self" type="application/rss+xml" />
	<link>http://flexoop.com</link>
	<description>Flex, AIR, ColdFusion, and everything in between</description>
	<lastBuildDate>Tue, 13 Jul 2010 03:56:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dedupe ArrayCollection Component</title>
		<link>http://flexoop.com/2008/11/dedupe-arraycollection-component/</link>
		<comments>http://flexoop.com/2008/11/dedupe-arraycollection-component/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 03:53:40 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[dedupeArrayCollection]]></category>

		<guid isPermaLink="false">http://flexfusion.archfamily.com/?p=52</guid>
		<description><![CDATA[Building off of my last post, I thought I might as well create a deduped arraycollection as well, just in case anyone wanted to use the data for something other than a combobox.  The implementation for this component is very similar to that of the combobox.  The DedupeArrayCollection allows you to pass it an array [...]]]></description>
			<content:encoded><![CDATA[<p>Building off of my <a title="last post" href="http://flexfusion.archfamily.com/2008/11/deduped-combobox-component/" target="_self">last post</a>, I thought I might as well create a deduped arraycollection as well, just in case anyone wanted to use the data for something other than a combobox.  The implementation for this component is very similar to that of the combobox.  The DedupeArrayCollection allows you to pass it an array (one that has some kind of properties to each of the items within it), then set the dedupeProperty to whatever field you wish to dedupe.</p>
<p>The DedupeArrayCollection:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">archfamily</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">CollectionEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DedupeArrayCollection <span style="color: #0066CC;">extends</span> ArrayCollection <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dedupeProperty:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> dedupeProperty<span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_dedupeProperty = value;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">source</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">source</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> dedupeProperty<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _dedupeProperty;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * 
		 * Needed to override the standard dataprovider in order to reset
		 * the duplicate value each time
		 * 
		 */</span>
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> source<span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> _returnArray:<span style="color: #0066CC;">Array</span> = value;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&amp;&amp;</span> dedupeProperty.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> _map:Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				value.<span style="color: #b1b100;">forEach</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span> item:<span style="color: #66cc66;">*</span>, <span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, <span style="color: #0066CC;">array</span>:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
					_map<span style="color: #66cc66;">&#91;</span> item<span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span> = item; <span style="color: #808080; font-style: italic;">// in the loop, this == dedupeProperty</span>
				<span style="color: #66cc66;">&#125;</span>, dedupeProperty <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				_returnArray = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
				<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">object</span>:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> _map <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					_returnArray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">object</span> <span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">super</span>.<span style="color: #006600;">source</span> = _returnArray;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DedupeArrayCollection<span style="color: #66cc66;">&#40;</span> source:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span> source <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The implementation of the arraycollection:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span> xmlns:archfamily=<span style="color: #ff0000;">&quot;com.archfamily.*&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">archfamily</span>.<span style="color: #006600;">DedupeArrayCollection</span>;
&nbsp;
			<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ac:DedupeArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> DedupeArrayCollection<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#91;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;car&quot;</span>, total: <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;bus&quot;</span>, total: <span style="color: #cc66cc;">200</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;bike&quot;</span>, total: <span style="color: #cc66cc;">300</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;train&quot;</span>, total: <span style="color: #cc66cc;">200</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;boat&quot;</span>, total: <span style="color: #cc66cc;">400</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;car&quot;</span>, total: <span style="color: #cc66cc;">500</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;bus&quot;</span>, total: <span style="color: #cc66cc;">200</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;convertible&quot;</span>, total: <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;gizmo&quot;</span>, total: <span style="color: #cc66cc;">300</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;boat&quot;</span>, total: <span style="color: #cc66cc;">300</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;car&quot;</span>, total: <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;dune buggy&quot;</span>, total:<span style="color: #cc66cc;">300</span> <span style="color: #66cc66;">&#125;</span>,<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">name</span>: <span style="color: #ff0000;">&quot;motorcycle&quot;</span>, total: <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				ac.<span style="color: #006600;">dedupeProperty</span> = <span style="color: #ff0000;">&quot;total&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>			
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:ComboBox id=<span style="color: #ff0000;">&quot;testing&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{ ac }&quot;</span> labelField=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>The only thing I would probably change is to figure out what event needs to fire when my dedupeProperty is set to get the arraycollection to reload the source.  Currently I&#8217;m just setting the source to itself so that the event fires and reloads the arraycollection, but just firing the event would probably be less overhead.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/11/dedupe-arraycollection-component/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
