<?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>Flex notes &#187; Flex 4</title>
	<atom:link href="http://www.robertbak.com/wordpress/category/flex-4/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.robertbak.com/wordpress</link>
	<description>My notes on Flex related topics</description>
	<lastBuildDate>Thu, 10 Nov 2011 10:49:53 +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>Generating PDF-s on the client side (including non-latin chars)</title>
		<link>http://www.robertbak.com/wordpress/2011/11/generating-pdf-s-on-the-client-side-including-non-latin-chars/</link>
		<comments>http://www.robertbak.com/wordpress/2011/11/generating-pdf-s-on-the-client-side-including-non-latin-chars/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 09:59:54 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[polskie znaki]]></category>
		<category><![CDATA[purepdf]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=435</guid>
		<description><![CDATA[This seems to come up every once in a while, especially outside US and UK. People start looking at the PDF generating libraries, and find that when they use a non-latin character it stops to work. It needs some special care but it is really easy to get it working, I&#8217;m going to show how [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>This seems to come up every once in a while, especially outside US and UK. People start looking at the PDF generating libraries, and find that when they use a non-latin character it stops to work. It needs some special care but it is really easy to get it working, I&#8217;m going to show how to do it, step by step, when using purepdf (a port of iText</p>
<h3>Getting ready</h3>
<p>You can find purepdf on <a href="http://code.google.com/p/purepdf/downloads/list">google code</a>. Once you download the zip you&#8217;ll find <em>purePDF.swc</em> and <em>purePDFont.swc</em>, for this example you&#8217;ll only need the first one so put it in your projects lib folder and you&#8217;re ready.<br />
The next thing you need is a font to use, I&#8217;ll be using <em>Ubuntu-L.ttf</em> which can be downloaded from <a href="http://font.ubuntu.com/">font.ubuntu.com</a>, just drop it in the project. You can use any font, as long as it supports the charset you&#8217;ll be using. At this point my project looks something like this:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2011/11/testingPDF1.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2011/11/testingPDF1.png" alt="" title="testingPDF1" width="233" height="206" class="aligncenter size-full wp-image-437" /></a><br />
<span id="more-435"></span></p>
<h3>Flex stuff</h3>
<p>To make the example work, we need some basic UI which, in the example, begins and ends with:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;TI&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;ążółć - works!&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> click=<span style="color: #ff0000;">&quot;createPDF()&quot;</span> label=<span style="color: #ff0000;">&quot;Generate PDF&quot;</span> y=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #66cc66;">/&gt;</span></div></div>
<p>As you can see, the text has some polish characters (as Flex text is UTF encoded there&#8217;s no problem with putting what you need there). The other thing worth noting is that we&#8217;re going to be creating the PDF after a click, that&#8217;s important as we want to save the pdf to the user system and that&#8217;s only possible when the <em>save</em> function is being called after an user interaction.</p>
<p>What&#8217;s left to do now is embedding the font:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;Ubuntu-L.ttf&quot;</span>, mimeType=<span style="color: #ff0000;">&quot;application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> embeddedFont: <span style="color: #000000; font-weight: bold;">Class</span>;</div></div>
<p>The mineType is required to stop Flex from handling the fonts as a font  <a class="simple-footnote" title="Without it you&#8217;ll get a message like &#8220;font transcoding requires you to specify &#8216;fontName&#8217; and one of &#8216;source&#8217;, &#8216;systemFont&#8217;, or &#8216;sourceList&#8217;&#8221;" id="return-note-435-1" href="#note-435-1"><sup>1</sup></a>. That&#8217;s all the setup we need no we can get to the purepdf code.</p>
<h3>Purepdf code</h3>
<p>The code that&#8217;s needed to start using the font and generatign the pdf takes around 10 lines, I&#8217;ll paste it first and than add comments.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">protected <span style="color: #000000; font-weight: bold;">function</span> createPDF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Prepare the font </span><br />
&nbsp; &nbsp;FontsResourceFactory.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">registerFont</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;newFont.otf&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> embeddedFont<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> bf: BaseFont = BaseFont.<span style="color: #006600;">createFont</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;newFont.otf&quot;</span>, BaseFont.<span style="color: #006600;">IDENTITY_H</span>, BaseFont.<span style="color: #006600;">EMBEDDED</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// parameters are:</span><br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// family, font-size, style, color, BaseFont</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">font</span>: org.<span style="color: #006600;">purepdf</span>.<span style="color: #0066CC;">Font</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;= <span style="color: #000000; font-weight: bold;">new</span> org.<span style="color: #006600;">purepdf</span>.<span style="color: #0066CC;">Font</span><span style="color: #66cc66;">&#40;</span> org.<span style="color: #006600;">purepdf</span>.<span style="color: #0066CC;">Font</span>.<span style="color: #0066CC;">UNDEFINED</span>, <span style="color: #cc66cc;">24</span>, -<span style="color: #cc66cc;">1</span>, RGBColor.<span style="color: #006600;">BLACK</span>, bf <span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> buffer:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> writer:PdfWriter = PdfWriter.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span> buffer, PageSize.<span style="color: #006600;">A4</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> doc:PdfDocument = writer.<span style="color: #006600;">pdfDocument</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;doc.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// When creating a paragraph &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// add the font parameter</span><br />
&nbsp; &nbsp;doc.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #66cc66;">&#40;</span>TI.<span style="color: #0066CC;">text</span>,<span style="color: #0066CC;">font</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;doc.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// save the file</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> f: FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;f.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span> buffer, <span style="color: #ff0000;">&quot;test.pdf&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>In lines <em>4-9</em> we&#8217;re using the embedded font file to create an instance of an <em>org.purepdf.Font</em>, that&#8217;s all you need to do to start using the font. The rest of the code is standard purepdf code.</p>
<p>11 &#8211; creates a buffer to hold the pdf file</p>
<p>12 &#8211; creates a <a href="http://www.sephiroth.it/purepdf/asdoc-output/org/purepdf/pdf/PdfWriter.html#create()">PDFWriter</a> linked with that buffer and sets the size of the pdf page</p>
<p>13 &#8211; gets the <a href="http://www.sephiroth.it/purepdf/asdoc-output/org/purepdf/pdf/PdfDocument.html">PDFDocument</a> from the writer</p>
<p>14 &#8211; opens the document</p>
<p><strong>15</strong> &#8211; adds a <a href="http://www.sephiroth.it/purepdf/asdoc-output/org/purepdf/elements/Paragraph.html">paragraph</a> to the open document. Here&#8217;s the important change if you already have some code written, you need to set the second parameter which is the font you&#8217;re wanting to use. If it supports the chars you&#8217;re using there will be no problem.</p>
<p>16 &#8211; closes the document</p>
<p>and 20-21 save the document to the user filesystem.</p>
<p>That&#8217;s it, the PDF you get in result looks something like this:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2011/11/testingPDF2.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2011/11/testingPDF2-300x59.png" alt="" title="testingPDF2" width="300" height="59" class="aligncenter size-medium wp-image-450" /></a></p>
<p>Hopefully this get&#8217;s people started. You can find many more examples and tutorials on the <a href="http://code.google.com/p/purepdf/w/list">google code</a> page for the project.</p>
<p><a href="http://dl.dropbox.com/u/207892/Flex/TestingPurePDF.fxp">Download source code.</a></p>
<div class="shr-publisher-435"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-435-1">Without it you&#8217;ll get a message like &#8220;font transcoding requires you to specify &#8216;fontName&#8217; and one of &#8216;source&#8217;, &#8216;systemFont&#8217;, or &#8216;sourceList&#8217;&#8221; <a href="#return-note-435-1">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2011/11/generating-pdf-s-on-the-client-side-including-non-latin-chars/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using constants in Flex CSS &#8211; with compile time error checking</title>
		<link>http://www.robertbak.com/wordpress/2011/10/using-constants-in-flex-css-with-compile-time-error-checking/</link>
		<comments>http://www.robertbak.com/wordpress/2011/10/using-constants-in-flex-css-with-compile-time-error-checking/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 20:35:31 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Flex 4]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=394</guid>
		<description><![CDATA[One of the problems with CSS is that in involves a lot of copy&#038;paste. Having multiple selectors which share a common property value (like a font color) is common, but in CSS you still need to have an individual color for each selector. So you end up with code that looks like this: s&#124;TextArea&#123; &#160; [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>One of the problems with CSS is that in involves a lot of copy&#038;paste. Having multiple selectors which share a common property value (like a font color) is common, but in CSS you still need to have an individual color for each selector. So you end up with code that looks like this:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">s<span style="color: #66cc66;">|</span>TextArea<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">color</span>:<span style="color: #808080; font-style: italic;">#eeeeee; &nbsp;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
s<span style="color: #66cc66;">|</span><span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">color</span>:<span style="color: #808080; font-style: italic;">#eeeeee; /* the same color as above*/ </span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Which is ok, but involves a lot of searching and replacing and careful analysis of the changes being made. I&#8217;ve been thinking about a way to put constants in there for a while and finally found a nice one today, while reading documentation for Flex 4.5. It&#8217;s really simple to use and has an added bonus &#8211; the compiler will make sure that the consts are actually defined, which should help with maintainability. </p>
<h3>Defining the constants</h3>
<p>Let&#8217;s start by defining the constants and their value. You need to create a new actionscript file (in my case <em>style\StyleConstants.as</em>), than throw away all the code that&#8217;s inside (eg. the package and class definitions), and define a const inside, we&#8217;ll use the file later.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* file: style\StyleConstants.as */</span><br />
<span style="color: #0066CC;">private</span> const someColorConstant:uint = 0xff0000;</div></div>
<p>Please notice that the variable can be private and will still work (it can also be public).</p>
<h3>Putting Actionscript variables in CSS &#8211; PropertyReference</h3>
<p>Looking at the Flex CSS documentation I&#8217;ve found that there&#8217;s a new keyword that you can use in Flex 4 CSS &#8211; <a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf62883-7ff2.html#WSda78ed3a750d6b8f679c5d39121cfd96fd4-8000">PropertyReference</a>. Since the docs say that &#8220;You can use document properties in your CSS&#8221; we&#8217;re going to do just that. The CSS class will be the modification of the one at the top, I&#8217;ll put it in <em>style\Style.css</em> and replace the colors with a pointer to the const declared above.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* file: style\Style.css */</span><br />
<span style="color: #66cc66;">@</span>namespace s <span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>;<br />
<span style="color: #66cc66;">@</span>namespace mx <span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span>;<br />
<br />
s<span style="color: #66cc66;">|</span>TextArea<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">color</span>:PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;someColorConstant&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
s<span style="color: #66cc66;">|</span><span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">color</span>:PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;someColorConstant&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p><span id="more-394"></span></p>
<h3>Getting it all together</h3>
<p>The last thing left to do is creating the application that will use the style, it&#8217;s also very basic.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- <span style="color: #808080; font-style: italic;">// STYLE --&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Style source=<span style="color: #ff0000;">&quot;style/style.css&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include <span style="color: #ff0000;">&quot;style/StyleConstants.as&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- <span style="color: #808080; font-style: italic;">// STYLE END --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> label=<span style="color: #ff0000;">&quot;Some button&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextArea x=<span style="color: #ff0000;">&quot;100&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Some text&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see, inside the main Application file, we import the css the regular way, the only addition is the include in line 9, which puts all the constants defined inside the <em>StyleConstants.as</em> inside the Application, allowing the PropertyReference to find them. Once you run this app you should see a great UI looking like this:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/FinalApp.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/FinalApp.png" alt="" title="FinalApp" width="307" height="34" class="aligncenter size-full wp-image-418" /></a><br />
Which does exactly what it should &#8211; uses the same color for both the Button and TextArea.</p>
<h3>Compile time checking?</h3>
<p>Yup. If you mess up you&#8217;re going to get a message from the compiler himself.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// change the css to:</span><br />
s<span style="color: #66cc66;">|</span><span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">color</span>:PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;someColorConstantWithAWrongName&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Will get you:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/error_message.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/error_message.png" alt="" title="error_message" width="467" height="43" class="aligncenter size-full wp-image-421" /></a><br />
Which is really nice.</p>
<h3>Notes</h3>
<p>A few things to keep in mind:<br />
1) This will not work with Flex 3.<br />
2) You need to put the links to the CSS and consts in the main application file.<br />
3) You can use a var instead of a const when defining the values. This will allow you to change the style during runtime, but keep in mind that this will not update the styles of the components that were already created but only the newly created ones.<br />
So the code below</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* Change the file: style\StyleConstants.as to */</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> someColorConstant:uint = 0xff0000;<br />
<br />
<span style="color: #808080; font-style: italic;">/** add a click handler in the main application **/</span><br />
protected <span style="color: #000000; font-weight: bold;">function</span> buttonClick<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">someColorConstant</span> = 0x0000ff;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> newButton:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newButton.<span style="color: #006600;">label</span> = <span style="color: #ff0000;">&quot;New button&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addElement</span><span style="color: #66cc66;">&#40;</span>newButton<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div></div>
<p>Will get you this:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/newButton.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2011/10/newButton.png" alt="" title="newButton" width="312" height="39" class="aligncenter size-full wp-image-427" /></a><br />
4) This allows you to set more than just simple values, allowing you to get back a functionality described at <a href="http://blog.flexexamples.com/2009/08/05/changing-the-opening-and-closing-easing-functions-on-a-halo-combobox-control-in-flex-4/">Flex Examples (Changing the opening and closing easing functions &#8230;)</a> using the code below.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// file style\StyleConstants.as</span><br />
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">effects</span>.<span style="color: #006600;">easing</span>.<span style="color: #006600;">Bounce</span>;<br />
<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> definedOpenEasing:<span style="color: #000000; font-weight: bold;">Function</span> &nbsp;= mx.<span style="color: #006600;">effects</span>.<span style="color: #006600;">easing</span>.<span style="color: #006600;">Bounce</span>.<span style="color: #006600;">easeOut</span>;<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> definedCloseEasing:<span style="color: #000000; font-weight: bold;">Function</span> &nbsp;= mx.<span style="color: #006600;">effects</span>.<span style="color: #006600;">easing</span>.<span style="color: #006600;">Bounce</span>.<span style="color: #006600;">easeIn</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">// file style\Style.css</span><br />
mx<span style="color: #66cc66;">|</span>ComboBox <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; openDuration: <span style="color: #cc66cc;">1000</span>;<br />
&nbsp; &nbsp; openEasingFunction: PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;definedOpenEasing&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; closeDuration: <span style="color: #cc66cc;">1000</span>;<br />
&nbsp; &nbsp; closeEasingFunction: PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;definedCloseEasing&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; alternatingItemColors: <span style="color: #808080; font-style: italic;">#DFDFDF, #EEEEEE;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>5) For other ways that create similar results, check <a href="http://stackoverflow.com/questions/2292127/how-to-have-constants-in-flex-css-files">stackoverflow.com</a></p>
<p><a href="http://robertbak.com/flexsamples/PropertyReference.fxp">Download source code.</a></p>
<div class="shr-publisher-394"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2011/10/using-constants-in-flex-css-with-compile-time-error-checking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet &#8211; Disabling paste on spark TexInput</title>
		<link>http://www.robertbak.com/wordpress/2011/03/snippet-disabling-paste-on-spark-texinput/</link>
		<comments>http://www.robertbak.com/wordpress/2011/03/snippet-disabling-paste-on-spark-texinput/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 01:23:31 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[copy and paste]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[TextArea]]></category>
		<category><![CDATA[TextInput]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=246</guid>
		<description><![CDATA[It&#8217;s a common requirement for e-mail or password inputs &#8211; the second input should not be copy pasted from the first one, to make sure it&#8217;s what the user wanted to put in. When using spark my Flex 3 method didn&#8217;t work, so just in case someone needs to do the same thing, here&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>It&#8217;s a common requirement for e-mail or password inputs &#8211; the second input should not be copy pasted from the first one, to make sure it&#8217;s what the user wanted to put in. When using spark my Flex 3 method didn&#8217;t work, so just in case someone needs to do the same thing, here&#8217;s the code for spark components:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:TextInput<br />
&nbsp; &nbsp;change=<span style="color: #ff0000;">&quot;if (event.operation is PasteOperation) <br />
&nbsp; &nbsp;(event.target as SkinnableTextBase).text = '' &quot;</span><br />
<span style="color: #66cc66;">/&gt;</span></div></div>
<p>It will also work with a TextArea.</p>
<div class="shr-publisher-246"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2011/03/snippet-disabling-paste-on-spark-texinput/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spell checking in Flex (with support for multiple languages)</title>
		<link>http://www.robertbak.com/wordpress/2010/11/spell-checking-in-flex-with-support-for-multiple-languages/</link>
		<comments>http://www.robertbak.com/wordpress/2010/11/spell-checking-in-flex-with-support-for-multiple-languages/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 11:21:37 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=217</guid>
		<description><![CDATA[A while ago the way to go, if you needed spell checking in Flash or Flex was Grant Skinners Spelling Plus Library (which still has a lot to offer, especially for Web applications, as it&#8217;s much smaller than the Adobe library). But, for a while now, Adobe has been working on their own project, called [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p style="text-align: justify;">A while ago the way to go, if you needed spell checking in Flash or Flex was Grant Skinners <a href="http://gskinner.com/products/spl/about.php">Spelling Plus Library</a> (which still has a lot to offer, especially for Web applications, as it&#8217;s much smaller than the Adobe library). But, for a while now, Adobe has been working on their own project, called Squiggly, which I&#8217;m going to use. </p>
<h3>The Squiggly library</h3>
<p style="text-align: justify;">You can download the library files from <a href="http://labs.adobe.com/downloads/squiggly.html">Adobe Labs</a>. After uncompressing the .zip file you&#8217;ll find three files in the libs folder. The one you need for this tutorial is &#8220;<i>AdobeSpellingUIEx.swc</i>&#8221; &#8211; it&#8217;s the Flex 4 version for simple integration, so just put it in your <i>libs</i> folder. The &#8220;<i>AdobeSpellingUI.swc</i>&#8221; is what you would use if your target would be a Flex 3 application. You should use only one of them as putting both in your <i>libs</i> might cause troubles. The third file is used when working with more advanced options given by the library.</p>
<p><a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/plikiSqu.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/plikiSqu.png" alt="" title="plikiSqu" width="187" height="72" class="aligncenter size-full wp-image-239" /></a><br />
 <span id="more-217"></span></p>
<h3>Getting additional dictionaries</h3>
<p style="text-align: justify;">While it&#8217;s nice to be able to spell check English words it doesn&#8217;t solve the issue for everyone. Although Adobe seems to discourage using the library with most languages, I&#8217;ve had a really good experience while using it with Polish language. So let&#8217;s take a look on how to install, and use, additional dictionaries. </p>
<p style="text-align: justify;">First thing you need to do is get the new dictionary. There are many places that can provide you with dictionary files, I usually go to the dictionary listing on <a href="http://wiki.services.openoffice.org/wiki/Dictionaries">Open Office wiki</a> <a class="simple-footnote" title="Please remember that dictionaries have different licenses, so you want to check them carefully before using them in any commercial software." id="return-note-217-1" href="#note-217-1"><sup>1</sup></a>. There&#8217;s sometimes more than one set of files available for a given language, but what you&#8217;re looking for is usually just the spelling part, which consists of two files – one with a <em>.aff</em> extension and one with <em>.dic</em>. The rule is that the first part of the file names will be the language code, so for English spellchecker you might need &#8220;<em>en_US.aff</em>&#8221; and &#8220;<em>en_US.dic</em>&#8221; and for Polish it would be &#8220;<em>pl_PL.aff</em>&#8221; and &#8220;<em>pl_PL.dic</em>&#8220;. In my project I&#8217;m going to use both, so I&#8217;ll just put them in some directory. Here&#8217;s how it looks:</p>
<p><a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/spellcheckerDirStruct.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/spellcheckerDirStruct.png" alt="" title="spellcheckerDirStruct" width="165" height="160" class="aligncenter size-full wp-image-227" /></a></p>
<h3>Creating a dictionary configuration file</h3>
<p style="text-align: justify;">The structure of the configuration file is fairy simple, and more ore less, only points to the files downloaded above, it&#8217;s included in the project but just for reference, here&#8217;s how to define the support for two languages.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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;">'UTF-8'</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>SpellingConfig<span style="color: #66cc66;">&gt;</span><br />
&nbsp; <span style="color: #66cc66;">&lt;</span>LanguageResource <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;English&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; languageCode=<span style="color: #ff0000;">&quot;en_US&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ruleFile=<span style="color: #ff0000;">&quot;assets/dict/en_US/en_US.aff&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dictionaryFile=<span style="color: #ff0000;">&quot;assets/dict/en_US/en_US.dic&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; <span style="color: #66cc66;">&lt;</span>LanguageResource <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;Polski&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; languageCode=<span style="color: #ff0000;">&quot;pl_PL&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ruleFile=<span style="color: #ff0000;">&quot;assets/dict/pl_PL/pl_PL.aff&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dictionaryFile=<span style="color: #ff0000;">&quot;assets/dict/pl_PL/pl_PL.dic&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>SpellingConfig<span style="color: #66cc66;">&gt;</span></div></div>
<h3>Full project structure</h3>
<p style="text-align: justify;">Now we have all the files ready, and can start coding. Here&#8217;s how my project looks:</p>
<p><a  href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/fullProject.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/fullProject.png" alt="" title="fullProject" width="213" height="305" class="aligncenter size-full wp-image-254" /></a></p>
<p style="text-align: justify;">As you can see the project is using the new Flex SDK version named &#8220;Hero&#8221;, but it was also tested with SDK 4.1. The project downloadable at the end of this article has been created in the new version of Flash Builder &#8220;Burrito&#8221;, which includes the new SDK, and which you can download from <a href="http://labs.adobe.com/technologies/flashbuilder_burrito/">Adobe Labs</a> </p>
<h3>The code</h3>
<p style="text-align: justify;">To get basic spellchecking to work you don&#8217;t need to do a whole lot. I&#8217;ll paste the whole code first, and than explain what happens.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;creationComplete=<span style="color: #ff0000;">&quot;creationCompleteHandler()&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- VIEW --<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextArea id=<span style="color: #ff0000;">&quot;myTextArea&quot;</span> bottom=<span style="color: #ff0000;">&quot;50&quot;</span> &nbsp;top=<span style="color: #ff0000;">&quot;0&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup &nbsp;<span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;50&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Switch to pl_PL&quot;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; click=<span style="color: #ff0000;">&quot;polishButton_clickHandler()&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Switch to en_US&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; click=<span style="color: #ff0000;">&quot;englishButton_clickHandler()&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">linguistics</span>.<span style="color: #006600;">spelling</span>.<span style="color: #006600;">SpellUI</span>;&nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> polishButton_clickHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpellUI.<span style="color: #006600;">disableSpelling</span><span style="color: #66cc66;">&#40;</span>myTextArea<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpellUI.<span style="color: #006600;">enableSpelling</span><span style="color: #66cc66;">&#40;</span>myTextArea,<span style="color: #ff0000;">&quot;pl_PL&quot;</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> englishButton_clickHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpellUI.<span style="color: #006600;">disableSpelling</span><span style="color: #66cc66;">&#40;</span>myTextArea<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpellUI.<span style="color: #006600;">enableSpelling</span><span style="color: #66cc66;">&#40;</span>myTextArea,<span style="color: #ff0000;">&quot;en_US&quot;</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> creationCompleteHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpellUI.<span style="color: #006600;">spellingConfigUrl</span> = <span style="color: #ff0000;">&quot;assets/dict/SpellingConfig.xml&quot;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></div>
<p style="text-align: justify;"> The first thing you need to do is configure the spell checker by providing it with an XML configuration you have created. That&#8217;s what happens in the <i>creationCompleteHandler</i>. After that you just need to call the <i>enableSpelling</i> function with two parameters: first is the id of a component which should be spell checked, and the second one specifies the language which should be used. The <i>disableSpelling</i> function removes the spell checking, I&#8217;ve noticed you need to call it before setting a new language, otherwise it will not change. With just this few lines of code you get a fully functional spell checker. Here&#8217;s how it looks when switching languages:
<p>
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/kot.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/kot.png" alt="" title="kot" width="222" height="53" class="aligncenter size-full wp-image-269" /></a><br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/cat.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/cat.png" alt="" title="cat" width="223" height="54" class="aligncenter size-full wp-image-270" /></a></p>
<p style="text-align: justify;">If you look at code, you might also notice that the you don&#8217;t need to create a new object of class SpellUI, all the functions are static.</p>
<h3>Final notes</h3>
<p style="text-align: justify;">A modern spell checking library would not be complete without a way to suggest proper spelling, and this also works out of the box, you just need to right click on an underlined word to get them. </p>
<p><a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/righClickSuggestions.png"><img src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/11/righClickSuggestions.png" alt="" title="righClickSuggestions" width="156" height="176" class="aligncenter size-full wp-image-273" /></a></p>
<p style="text-align: justify;">But there are some things to keep in mind when starting to use this library. First, it&#8217;s still in development an a lot can change, including the way you use the library. Second, there are some issues with efficiency, the dictionaries are quite big (the Polish one is 4MB, the en_US around 600kB) and even after downloading them the parsing process freezes the application for a noticeable time. But still, a long needed addition to the Flex ecosystem is here, and it&#8217;s really easy to use.</p >
<p><a href="http://robertbak.com/flexsamples/FlexSquiggly.zip"><br />
Download source code.</a></p>
<div class="shr-publisher-217"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-217-1">Please remember that dictionaries have different licenses, so you want to check them carefully before using them in any commercial software. <a href="#return-note-217-1">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2010/11/spell-checking-in-flex-with-support-for-multiple-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From photoshop design to a Flex 4 skin</title>
		<link>http://www.robertbak.com/wordpress/2010/03/from-photoshop-design-to-a-flex-4-skin/</link>
		<comments>http://www.robertbak.com/wordpress/2010/03/from-photoshop-design-to-a-flex-4-skin/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 18:03:36 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[skins flex4]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=133</guid>
		<description><![CDATA[When looking at some old project folders I&#8217;ve found one of the first skins I&#8217;ve created while starting with the Flex 4 skinning model, and I thought it might be an interesting case to look at, source code is included at the end of the post. It&#8217;s based on a really nice design done by [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>When looking at some old project folders I&#8217;ve found one of the first skins I&#8217;ve created while starting with the Flex 4 skinning model, and I thought it might be an interesting case to look at, source code is included at the end of the post. It&#8217;s based on a really nice design done by <a href="http://www.adrianpelletier.com/">Adrian Pelletier</a>. What we&#8217;ll try to do is create a button which looks more or less like one of his button designs:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/button-design.png"><img class="aligncenter size-full wp-image-129" title="button-design" src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/button-design.png" alt="" width="524" height="94" /></a><br />
What makes it a good design is not only the way it looks but also the way the Photoshop file is created &#8211; it&#8217;s mostly based on shapes and layer effects which are easy to translate to Flex skin code.<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/layers.png"><img class="aligncenter size-full wp-image-131" title="layers" src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/layers.png" alt="" width="219" height="115" /></a></p>
<h3>Styling a Flex 4 Button</h3>
<p>The Flex 4 skinning model is different from the one used in Flex 3, to keep the introduction short, let&#8217;s just say it&#8217;s now much easier to create programmatic skins, and you can do it with newly introduced MXML tags. If you ever used Degrafa to skin your components it&#8217;s should be fairly familiar, if not please check the example code. The basic usage is straight forward &#8211; you need to create a <em>mxml</em> file and you can start putting the new tags to design the skin.</p>
<p>Let&#8217;s start with the shadow behind the button, as you can see on the picture above it has 3 parts &#8211; a gradient fill, a stroke and an inner shadow, and all of them thrown on a shape of a rounded rectangle. Let&#8217;s translate this to graphic tags. First of we need that rounded rectangle, so we define a Rectangle with the corner radius using the new tags:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Rect radiusY=<span style="color: #ff0000;">&quot;24&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; radiusX=<span style="color: #ff0000;">&quot;24&quot;</span><span style="color: #66cc66;">/&gt;</span></div></div>
<p>That&#8217;s how easy it is to create shapes using the new syntax. Next we need to define a fill, which according to the Photoshop design is a linear gradient starting from color 0x0f2835 and ending with color 0&#215;153445. We also need an inner drop shadow on it, so let&#8217;s add it. We also need a stroke <strong>above</strong> all this, so we need to add another rectangle which will not have the drop shadow on it, and will define that gradient stroke, just like the design. A few minutes later we have:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Rect radiusY=<span style="color: #ff0000;">&quot;24&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; radiusX=<span style="color: #ff0000;">&quot;24&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x=<span style="color: #ff0000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y=<span style="color: #ff0000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;{this.width}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;{this.height}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:filters<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:DropShadowFilter inner=<span style="color: #ff0000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance=<span style="color: #ff0000;">&quot;0&quot;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strength=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:filters<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:fill<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:LinearGradient rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0x0f2835&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0x153445&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:LinearGradient<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:fill<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:Rect<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Rect radiusY=<span style="color: #ff0000;">&quot;24&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; radiusX=<span style="color: #ff0000;">&quot;24&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x=<span style="color: #ff0000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y=<span style="color: #ff0000;">&quot;0&quot;</span> &nbsp;alpha=<span style="color: #ff0000;">&quot;0.8&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;{this.width}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;{this.height}&quot;</span> <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:stroke<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:LinearGradientStroke rotation=<span style="color: #ff0000;">&quot;90&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;weight=<span style="color: #ff0000;">&quot;2&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pixelHinting=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0x102a39&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0x20516c&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:LinearGradientStroke<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:stroke<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:Rect<span style="color: #66cc66;">&gt;</span></div></div>
<p>It&#8217;s not the shortest listing, but remember that I&#8217;m only copying the settings from the design. The final flash result looks like this:<br />
<a href="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/shadow.png"><img class="aligncenter size-full wp-image-148" title="shadow" src="http://www.robertbak.com/wordpress/wp-content/uploads/2010/03/shadow.png" alt="" width="184" height="76" /></a></p>
<p>It&#8217;s almost a easy to create the rest of the design, take a look a the working button with some Flex magic thrown in to get nice transitions between states (<a href="http://robertbak.com/flexsamples/buttonSkin/source/index.html">viewsource</a> enabled), and after the jump, I&#8217;ll quickly point to different parts of the design which are used in the <i>ButtonSkin.mxml</i></p>
<h3>Result</h3>
<p> <iframe class="aligncenter size-full" src="http://robertbak.com/flexsamples/buttonSkin/SampleSkinApplication.html" style="height: 201px; width: 301px;" frameborder="0">Please upgrade your browser</iframe></p>
<h3>What makes a skin &#8211; looking at ButtonSkin.mxml</h3>
<p>First of you should define a component for which the skin is designed.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #66cc66;">&#91;</span>HostComponent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;spark.components.Button&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></div></div>
<p>Next you need to define all the states which are defined by the host component (you can check this info on <a href="http://help.adobe.com/en_US/Flex/4.0/langref/spark/components/Button.html#SkinStateSummary">livedocs</a>) which is done in this code:</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:states<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;up&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;down&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;over&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;disabled&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:states<span style="color: #66cc66;">&gt;</span></div></div>
<p>After that&#8217;s done you also need to put the parts of the skin that the host components assumes your skin will have (this is called <i>skinning contract</i> and I&#8217;ll write a post about it when I have some time). In the case of Button we need to display a single string (the button label as stated in <a href="http://help.adobe.com/en_US/Flex/4.0/langref/spark/components/Button.html#SkinPartSummary">livedocs</a>) we&#8217;re going to use a <i>Label</i> for that and give it an id of <i>labelDisplay</i> according to the contract.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;17&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;17&quot;</span> <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0xffffff&quot;</span> <br />
&nbsp; &nbsp; <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;{this.height}&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> id=<span style="color: #ff0000;">&quot;labelDisplay&quot;</span> <span style="color: #66cc66;">&gt;</span></div></div>
<p>Than we can start putting in the graphics, using the same tags we used while creating the shadow. The only additions is that the values of the gradients change depending on the state, thanks to the new state syntax in Flex 4 it&#8217;s much more readable &#8211; there&#8217;s a different color when the button is in an over state (<i>color.over</i>) and a different one when the button is in the down state (<i>color.down</i>)</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>mx:GradientEntry id=<span style="color: #ff0000;">&quot;ge1&quot;</span> <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;0x387dda&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">color</span>.<span style="color: #006600;">over</span>=<span style="color: #ff0000;">&quot;0x3e81de&quot;</span> <span style="color: #0066CC;">color</span>.<span style="color: #0066CC;">down</span>=<span style="color: #ff0000;">&quot;0x88bafe&quot;</span> <span style="color: #66cc66;">/&gt;</span></div></div>
<p>To add the smooth color fades between states we also define a bunch of transitions which work on our gradient entries.</p>
<div class="codecolorer-container actionscript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Transition &nbsp; fromState=<span style="color: #ff0000;">&quot;up&quot;</span> toState=<span style="color: #ff0000;">&quot;over&quot;</span> autoReverse=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>s:AnimateColor targets=<span style="color: #ff0000;">&quot;{[ge1, ge2, ge3, ge4]}&quot;</span> &nbsp;<span style="color: #0066CC;">duration</span>=<span style="color: #ff0000;">&quot;250&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp;<span style="color: #66cc66;">&lt;/</span>s:Transition<span style="color: #66cc66;">&gt;</span></div></div>
<p>Feel free to download the source code and play with it, hopefully it will be a good starting point.<br />
<a href="http://robertbak.com/flexsamples/buttonSkin/source/SampleSkin.zip"><br />
Download source code.</a></p>
<div class="shr-publisher-133"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2010/03/from-photoshop-design-to-a-flex-4-skin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Spark Group, SkinPart and Error 1020</title>
		<link>http://www.robertbak.com/wordpress/2010/02/spark-group-skinpart-and-error-1020/</link>
		<comments>http://www.robertbak.com/wordpress/2010/02/spark-group-skinpart-and-error-1020/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 15:12:33 +0000</pubDate>
		<dc:creator>Robert Bak</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[skinPart]]></category>
		<category><![CDATA[skins flex4 error]]></category>
		<guid isPermaLink="false">http://www.robertbak.com/wordpress/?p=21</guid>
		<description><![CDATA[I've added some SkinParts and it started throwing a strange error message on the definitions: 1020: Method marked override must override another method. ]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I&#8217;ve recently started a project that uses new Flex 4 skinning. It was going great until I&#8217;ve added some SkinParts and it started throwing a strange error message on those definitions :</p>
<blockquote><p>1020: Method marked override must override another method.</p></blockquote>
<p>After starring at it for a while with utter confusion, I&#8217;ve started to investigate what might be the problem. Turns out I was adding skin parts to a spark Group, and the documentation states:</p>
<blockquote><p>To improve performance and minimize application size,<br />
the Group container cannot be skinned.<br />
If you want to apply a skin, use the SkinnableContainer instead.</p></blockquote>
<p>Which is exactly what I needed to do. Too bad there was no hint about it in the error string.</p>
<div class="shr-publisher-21"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.robertbak.com/wordpress/2010/02/spark-group-skinpart-and-error-1020/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

