<?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>Sebastiaan Holtrop &#187; Uncategorized</title>
	<atom:link href="http://www.sebastiaanholtrop.com/archives/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sebastiaanholtrop.com</link>
	<description>Creating stuff that works...</description>
	<lastBuildDate>Mon, 08 Feb 2010 11:39:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex Application background gradient</title>
		<link>http://www.sebastiaanholtrop.com/archives/112</link>
		<comments>http://www.sebastiaanholtrop.com/archives/112#comments</comments>
		<pubDate>Mon, 08 Feb 2010 11:36:21 +0000</pubDate>
		<dc:creator>Sebastiaan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sebastiaanholtrop.com/?p=112</guid>
		<description><![CDATA[After doing some actionscript-only projects for a while I&#8217;m back working with Flex now. It&#8217;s good to not have to build my scrollbars and such entirely by hand.
Unfortunately, some things that take a few seconds in flash to build sometimes take a few hours in Flex, like this for instance:
I wanted a radial gradient graphic [...]]]></description>
			<content:encoded><![CDATA[<p>After doing some actionscript-only projects for a while I&#8217;m back working with Flex now. It&#8217;s good to not have to build my scrollbars and such entirely by hand.<br />
Unfortunately, some things that take a few seconds in flash to build sometimes take a few hours in Flex, like this for instance:</p>
<p>I wanted a radial gradient graphic as a background in my application. The Flex application tag supports linear gradients but not the radial one. I could set a huge graphic (png) as the backgroundImage for the Application, but that would add filesize to my swf file. I could extendApplication and override the updateDisplayList function and draw my graphic there, but I don&#8217;t think that&#8217;s the way to go either.</p>
<p>So I tried creating a programmatic skin which may sound like the right solution, but which styleable property do we need to attach the Classreference to? Here&#8217;s the solution:</p>
<p>Style the Application tag. Set the Classreference on the backgroundImage property (who would have guessed that one). Don&#8217;t forget to set the backgroundSize property to 100%, otherwise our graphic won&#8217;t stretch to the full size of the container.</p>

<div class="wp_codebox"><table><tr id="p1123"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p112code3"><pre class="actionscript" style="font-family:monospace;">Application <span style="color: #66cc66;">&#123;</span>
backgroundImage: ClassReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test.skins.ApplicationBackgroundSkin&quot;</span><span style="color: #66cc66;">&#41;</span>;
backgroundSize: <span style="color: #ff0000;">&quot;100%&quot;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Then create a programmatic skin class by extending the ProgrammaticSkin class and override the following functions:</p>

<div class="wp_codebox"><table><tr id="p1124"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p112code4"><pre class="actionscript" style="font-family:monospace;">override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> measuredWidth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">200</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> measuredHeight<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">200</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
protected override <span style="color: #000000; font-weight: bold;">function</span> updateDisplayList<span style="color: #66cc66;">&#40;</span>unscaledWidth:<span style="color: #0066CC;">Number</span>, unscaledHeight:<span style="color: #0066CC;">Number</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> mat:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> colors:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span>0xEAEAEA, 0xFFFFFF<span style="color: #66cc66;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">var</span> alphas:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">var</span> ratios:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
mat.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span>,<span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
graphics.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
graphics.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">RADIAL</span>, colors, alphas, ratios, mat<span style="color: #66cc66;">&#41;</span>;
graphics.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">200</span>,<span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
graphics.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Draw the graphic in the updateDisplayList function. Don&#8217;t forget to override the getters for measuredWidth and measuredHeight. If you don&#8217;t, the programmatic skin doesn&#8217;t have a width and height and the graphic wil not be visible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastiaanholtrop.com/archives/112/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
