<?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>SmartLogic Solutions Blog &#187; ComboBox</title>
	<atom:link href="http://blog.smartlogicsolutions.com/tag/combobox/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Displaying an Image in a ComboBox</title>
		<link>http://blog.smartlogicsolutions.com/2008/12/01/displaying-an-image-in-a-combobox/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/12/01/displaying-an-image-in-a-combobox/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 16:17:53 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[Image]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=392</guid>
		<description><![CDATA[I needed to display an Image inside of a ComboBox for a recent project. The image of a selectedItem needed to appear in the ComboBox when it is collapsed and the image needed to be specified as a String. I was surprised that a quick search didn&#8217;t find any components to allow this. The closest [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to display an Image inside of a ComboBox for a recent project.  The image of a selectedItem needed to appear in the ComboBox when it is collapsed and the image needed to be specified as a String.</p>
<p>I was surprised that a quick search didn&#8217;t find any components to allow this.  The closest was a <a href="http://flexibleexperiments.wordpress.com/2007/04/28/flex-201-combobox-with-icon-support/">post by Jason Hawryluk</a>, however this required the image to be embedded into the application.</p>
<p>So I simply extended ComboBox to include an Image within it, and added some sizing calculations so it would respect padding.  An example follows below:<br />
<span id="more-392"></span></p>
<p>[flash http://blog.smartlogicsolutions.com/wp-content/uploads/2008/11/ImageComboBox.swf H=150]</p>
<p>The <a href="http://blog.smartlogicsolutions.com/wp-content/uploads/2008/11/ImageComboBox.as">ImageComboBox class</a> </p>
<ol>
<li>Adds an Image in the <code>createChildren</code> method</li>
<li>Measures the available size the image can take up in the <code>measure</code> method</li>
<li>In the <code>updateDisplayList</code> method, if an item is selected:</li>
<ol>
<li>Sets the source for the Image</li>
<li>Places and sizes the Image based on calculations from <code>measure</code></li>
</ol>
</ol>
<p>In order to prevent the ComboBox from displaying &#8220;[object Object]&#8221; along with the image, be sure to include a label=&#8221;" property on the items in the <code>dataProvider</code> for the ComboBox.  The following code is the MXML main file for the embedded SWF above:</p>
<h4>Example MXML</h4>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">	            xmlns:sls=<span style="color: #ff0000;">&quot;com.slslabs.flex.controls.*&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;This demonstrates using the ImageComboBox&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;sls:ImageComboBox</span> width=<span style="color: #ff0000;">&quot;60&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;sls:dataProvider</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> url=<span style="color: #ff0000;">&quot;http://www.iconarchive.com/icons/iconshock/mario-bros/mario-32x32.png&quot;</span> label=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> url=<span style="color: #ff0000;">&quot;http://www.iconarchive.com/icons/iconshock/mario-bros/luigui-32x32.png&quot;</span> label=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> url=<span style="color: #ff0000;">&quot;http://www.iconarchive.com/icons/iconshock/mario-bros/start-32x32.png&quot;</span> label=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/sls:dataProvider</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;sls:itemRenderer</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Image</span> source=<span style="color: #ff0000;">&quot;{data.url}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/sls:itemRenderer</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/sls:ImageComboBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>I pushed the code into my first git repository <a href="http://github.com/gjastrab/imagecombobox/tree/master">at github</a>.  If you&#8217;re a git n00b, then after you&#8217;ve <a href="http://www.google.com/search?hl=en&#038;q=install+git&#038;btnG=Google+Search&#038;aq=f&#038;oq=">installed git</a> (or checked out the <a href="http://github.com/guides/using-the-egit-eclipse-plugin-with-github">Git Eclipse Plugin</a> &#8211; which I still need to do) then pull down the code by using the command:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">git clone git://github.com/gjastrab/imagecombobox.git</pre></div></div>

<p>If you aren&#8217;t on the git bandwagon yet, then just right-click and save as&#8230; to download the <a href="http://blog.smartlogicsolutions.com/wp-content/uploads/2008/11/ImageComboBox.as">ImageComboBox.as</a> file for now.</p>
<p>I plan on improving it soon to have it respect the positioning of a label or to optionally hide the label.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/09/25/rotate-effect-and-non-embedded-fonts-in-flex-4/" rel="bookmark" class="crp_title">Rotate Effect and Non Embedded Fonts in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/28/flex-4-login-form-component/" rel="bookmark" class="crp_title">Flex 4 Login Form Component</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/16/skinning-button-flex-4-fxg/" rel="bookmark" class="crp_title">Skinning A Button in Flex 4 Using FXG</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/19/creating-custom-flex-4-skinnable-component/" rel="bookmark" class="crp_title">Creating Your First Custom SkinnableComponent in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/16/creating-custom-layout-in-flex-4-gumbo/" rel="bookmark" class="crp_title">Creating a Custom Layout Class in Flex 4</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/12/01/displaying-an-image-in-a-combobox/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

