<?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>dndigital.net &#187; Image</title>
	<atom:link href="http://dndigital.net/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://dndigital.net</link>
	<description>Notes on Adobe Flash, Flex, AIR Development</description>
	<lastBuildDate>Mon, 07 May 2012 15:12:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Flex UIComponent subclass needs to resize images</title>
		<link>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/</link>
		<comments>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 12:57:17 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[UIComponent]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=15</guid>
		<description><![CDATA[The title could do with some improving &#8211; what I&#8217;m trying to say is that when subclassing UIComponent, any Image component instances need to be given an appropriate width/height. I have overlooked this time and time again, only to find that the image doesn&#8217;t appear &#8211; because it&#8217;s width and height are initialised to zero. [...]]]></description>
			<content:encoded><![CDATA[<p>The title could do with some improving &#8211; what I&#8217;m trying to say is that when subclassing UIComponent, any Image component instances need to be given an appropriate width/height. I have overlooked this time and time again, only to find that the image doesn&#8217;t appear &#8211; because it&#8217;s width and height are initialised to zero.</p>
<p>The following code will result in an image with zero width/height, so the image won&#8217;t show:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> img:Image = <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">source</span> = <span style="color: #ff0000;">&quot;myfile.jpg&quot;</span>;</pre></div></div>

<p>Solutions:</p>
<ol>
<li>Assign specific values for width and height:

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">100</span>;
img.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">100</span>;</pre></div></div>

</li>
<li>Set the &#8216;scaleContent&#8217; property to false &#8211; the image will then resize its container automatically, once it has loaded. Note that this technique <strong>has no effect if loading image from non-trusted domains</strong>!

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #006600;">scaleContent</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// or, if loading cross-domain, provided a crossdomain policy file allows access</span>
img.<span style="color: #006600;">trustContent</span> = <span style="color: #000000; font-weight: bold;">true</span>;
img.<span style="color: #006600;">scaleContent</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

</li>
<li>Use an event listener to detect when the image has finished loading, then assign the correct width and height. <strong>Again, this will only work if the image has been loaded from a trusted domain.</strong>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onImageComplete<span style="color: #66cc66;">&#41;</span>;
&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> onImageComplete<span style="color: #66cc66;">&#40;</span>evt:Event<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> img:Image = evt.<span style="color: #0066CC;">target</span> as Image;
    img.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onImageComplete<span style="color: #66cc66;">&#41;</span>;
    img.<span style="color: #0066CC;">width</span> = img.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">width</span>;
    img.<span style="color: #0066CC;">height</span> = img.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">height</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
</ol>
<p>I&#8217;ve mainly blogged about it so I remember the next time I write some code &#8211; but maybe it will also help somebody else debug their missing image problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

