<?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"
	>

<channel>
	<title>AH:</title>
	<atom:link href="http://www.hulstkamp.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hulstkamp.com</link>
	<description>andy hulstkamp blog about rich internet applications, flex, flash, java, webapps, web, code, experiments</description>
	<pubDate>Sun, 31 Jul 2011 07:24:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Experience using Google App Engine, Spring MVC  and Flex</title>
		<link>http://www.hulstkamp.com/2011/04/12/experience-with-google-app-engine-spring-mvc-and-flex/613</link>
		<comments>http://www.hulstkamp.com/2011/04/12/experience-with-google-app-engine-spring-mvc-and-flex/613#comments</comments>
		<pubDate>Tue, 12 Apr 2011 16:15:49 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[Google App Engine]]></category>

		<category><![CDATA[Spring]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[cloud]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[spring mvc]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=613</guid>
		<description><![CDATA[I had a look at Google App engine and some of the new features in Spring 3 (MVC). 
I decided to create a platform for city ratings and –rankings. I polished the whole thing a bit in the hope to attract some visitors. I wonder if I can get some peaks in traffic to see [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span lang="EN-US">I had a look at Google App engine and some of the new features in Spring 3 (MVC). </span></p>
<p class="MsoNormal"><span lang="EN-US">I decided to create a platform for city ratings and –rankings. I polished the whole thing a bit in the hope to attract some visitors. I wonder if I can get some peaks in traffic to see how this service will perform in GAE under load outside of a stress test.</span></p>
<p class="MsoNormal"><span lang="EN-US">To see what I&#8217;m talking abput, a first version is up and running at <a href="http://www.cityclash.org">CityClash.org</a>.<span> </span>To read about my experience with Google App Engine read on after the screenshot.</span></p>
<p class="MsoNormal"><a href="http://www.cityclash.org"><img class="aligncenter" title="CityClash city ratings and rankings" src="http://www.hulstkamp.com/byard/meta/cityclash/city-rating.png" alt="" width="498" height="301" /></a></p>
<p class="MsoNormal"><span lang="EN-US">Building CityClash.org involved a couple of interesting aspects towards Google App<span id="more-613"></span> Engine, the datastore and Spring MVC.</span></p>
<ul>
<li><span lang="EN-US">The usual CRUD ops</span></li>
<li><span lang="EN-US">Transactions</span></li>
<li><span lang="EN-US">Joins &amp; aggregation</span></li>
<li><span lang="EN-US">Long running processes</span></li>
<li><span lang="EN-GB">REST-style with JSON response </span></li>
<li><span lang="EN-US">External API calls</span></li>
<li><span lang="EN-US">Developing for scalability</span></li>
</ul>
<p class="MsoListParagraph"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">I used the </span><span lang="EN-GB"><a href="http://www.springsource.com/developer/sts"><span lang="EN-US">SpringSource Tool suite</span></a></span><span lang="EN-US"> with the GAE-Plugin for development.<span> Setting up </span>Spring with GAE was straightforward and worked as expected. Add the required jars and configure the spring project as you would normally do. Note, I’m referring to the MVC part of Spring and can’t speak for the other parts right now.</span></p>
<h2><span lang="EN-US">Spring 3 MVC</span></h2>
<p class="MsoNormal"><span lang="EN-US">The REST-features and Ajax-simplifications in Spring MVC worked in GAE  just fine. This stuff is really well done in Spring and a joy to work with.</span></p>
<h2><span lang="EN-US">Task queues in GAE</span></h2>
<p class="MsoNormal"><span lang="EN-US">Task queues in Google App Engine are a great way to speed up the user experience, by simply doing expensive work later and not during a user’s request. If some calculations need not to be done immediately task queues are worth considering.</span></p>
<p class="MsoNormal"><span lang="EN-US">When a city rating in CityClash comes in, I defer calculations of some statistical figures to a task queue. The user does not need to know about these figures immediately, it’s good enough when they get updated a couple of minutes later and the user gets a rather quick response.</span></p>
<p class="MsoNormal"><span lang="EN-US">Task queues are easy to set up. In a couple of lines you get a Queue from the Factory, create, configure the task and add it to the queue. The Queue will later invoke a HTTP-Request based on the Task. The actual work is then done in the handler that serves the request.</span></p>
<h2><span lang="EN-US">URL Fetch calling external apis</span></h2>
<p class="MsoNormal"><span lang="EN-US">For Internationalization purposes I need to translate the city names to the local language. In CityClash.org I currently support German and English. Via Geocoding I get the English name but I need the German name as well. For <em>Berne, Switzerland</em> I need <em>Bern, Schweiz</em> too. </span></p>
<p class="MsoNormal"><span lang="EN-US">In Google Maps I could invoke another request asking for the German name, but I was a bit worried to get over the quota or get blocked for invoking too many requests at a rate too high. For this reason and for the fun of it, I decided to use the Google Translate API to get the localized name.</span></p>
<p class="MsoNormal"><span lang="EN-US">If CityClash gets a rating from a city that had not been rated before, the Google Translate API gets invoked and fetches the German name once.<span> </span>This is simple and straightforward. Use java.net.URL to open a connection and parse the stream. To not block the user’s request I put this step in a task queue as well.</span></p>
<h2><span lang="EN-US">Memcache</span></h2>
<p class="MsoNormal"><span lang="EN-US">CC uses the cache as much as possible. I’m using the low level API. There’s not much to say about this. Put and get </span><span lang="EN-GB">Serializable objects, use expiration and be sure to have a fallback if values in the cache get lost: it’s a cache not a permanent store.</span></p>
<h2><span lang="EN-US">Datastore</span></h2>
<p class="MsoNormal"><span lang="EN-US">If you come from an SQL-background, then the datastore is probably the most difficult aspect to get used to. It took me a while to think out of the box and accept the limitations and embrace the blessings.</span></p>
<p class="MsoNormal"><span lang="EN-US">Here are a few key things to note from <strong>my newbie point of view and</strong> <strong>as of now</strong>:</span></p>
<ul>
<li><span lang="EN-US">Loose the SQL-mindset. Forget about complex joins, nested queries and aggregation. </span></li>
<li><span lang="EN-US">What you get is sort of a distributed Hashtable, optimized for reads. The datastore is organized <span> </span>in a fashion, that lets it efficiently scan and read data. Stuff like filters (&lt;,&lt;=,= etc.), order by, ancestors or keys can be applied to the queries. But there are limitations of how you can combine the filters, orders etc. too.</span></li>
<li><span lang="EN-US">As to expect, reads are fast, especially when using keys. </span></li>
<li><span lang="EN-US">Don’t spoil this by trying to work around the limitations regarding joins and aggregation. Doings loads of calculations in memory to mimic such behavior won’t scale well and will cost you cycles.</span></li>
<li><span lang="EN-US">Instead store the data in a fashion that embraces the usage pattern.<br />
</span></li>
<li><span lang="EN-US">Try to do calculations once, when writing. Prepare the data for simple, efficient reads.</span></li>
<li><span lang="EN-US">If writing takes too long try to delegate some stuff to task queues and do the hard work later.<br />
</span></li>
<li><span lang="EN-US">Accept and embrace denormalization. </span></li>
<li><span lang="EN-US">Use task queues and cron jobs where possible to do long running processes in the background. In CC lots of aggregation is done in the background.</span></li>
<li><span lang="EN-US">Writes are expensive, since they may need reorganization. Be aware of contention. </span></li>
<li><span lang="EN-US">If writes have the potential to cause contention, consider sharding or use smaller entity groups.<br />
</span></li>
<li><span lang="EN-US">Transactions are there but only spanning over the same entity group . I tried to stay away of transactions alltogether – and denormalize.</span></li>
<li><span lang="EN-US">I stayed away from JDO and JPA because I could. Where’s the point of having another abstraction layer over a HashMap? <span> </span>I used the low level API in conjunction with <a href="http://code.google.com/p/objectify-appengine/">objectify</a>, which itself makes for a very good documentation on the datastore.</span></li>
<li><span lang="EN-US">There&#8217;s no full text search. The most you will get is a filter-order combination to mimick a sclaed-down LIKE on crutches.<br />
</span></li>
</ul>
<p class="MsoNormal"><span lang="EN-US">Again, <strong>these are not necessarily best practices</strong>; they just reflect my take on the datastore of the appengine right now.<br />
</span></p>
<h1><span lang="EN-US">Mail</span></h1>
<p class="MsoNormal"><span lang="EN-US">Sending mail is a no brainer and works straight out of the box. The only restriction is that </span><span lang="EN-GB">the sender address of a message must be the email address of an administrator for the application.</span></p>
<h1><span lang="EN-GB">Development<span> </span>Server</span></h1>
<p class="MsoNormal"><span lang="EN-GB">I have yet to discover any inconsistencies between the development server and<span> </span>the appengine in terms of behaviour.<span> </span>The test skeleton<span> </span>is pretty good too.</span></p>
<h1><span lang="EN-GB">Flex</span></h1>
<p class="MsoNormal"><span lang="EN-GB">I didn’t bother to use the Spring Blaze integration. For the couple of requests and the few data I simply used the HTTPService.<span> </span>The new REST-full features paired with the JSON response made it easy to integrate Flex and Spring. Same applies to the Ajax-Calls through JQuery.</span></p>
<h1><span lang="EN-US">JSTL</span></h1>
<p class="MsoNormal"><span lang="EN-US">My experience was, that there are some minor issues with JSTL inside GAE. For example, I could not get hold of an object-reference via the var attribute inside the forEach-Tag.<span> </span>Possibly my fault and I didn’t bother too much since the index-based approach using the varStatus-Attribute works fine. Further the formatNumber-Tag didn’t work since its implementation apparently needs a reference to the session. I did not want to turn on sessions (</span><span lang="EN-GB"><a href="http://blog.afewguyscoding.com/2011/02/httpsession-google-app-engine/"><span lang="EN-US">backed by memcache and the datastore</span></a></span><span lang="EN-US">) just for this, so I formatted the numbers in advance to be consumed by the page building.</span></p>
<h1><span lang="EN-US">Conclusion</span></h1>
<p class="MsoNormal"><span lang="EN-US">So far I’m pretty impressed by GAE. It has restrictions and it took me some time to get used to the datastore first. But once you get the hang of it, things work out pretty straightforward. </span></p>
<p class="MsoNormal"><span lang="EN-US">And you get the advantages</span></p>
<ul>
<li><span lang="EN-US">Scalability (can’t really judge on this right now),</span></li>
<li><span lang="EN-US">Pay for what you use</span></li>
<li><span lang="EN-US">Easy App versioning</span></li>
<li><span lang="EN-US">No Server-Management and maintenance. </span></li>
</ul>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">While I can’t really judge on the first as of now, the last point especially, for me, is a real blessing. </span></p>
<p class="MsoNormal"><span lang="EN-US">After all, it depends </span><span lang="EN-GB">whether your app can live within the constraints of GAE (mainly the datastore). I’d say</span><span lang="EN-US"> Google App Engine is not the right tool for complex business applications as of now, but is a great environment for simple to moderately complex web-apps. For independent developers or startups the PaaS-approach might very well be the right thing.</span></p>
<p class="MsoNormal"><span lang="EN-US"><span> </span></span><span lang="EN-GB"><a href="http://www.carlosble.com/2010/11/goodbye-google-app-engine-gae/"><span lang="EN-US">Others</span></a></span><span lang="EN-GB"> </span><span lang="EN-US"><a href="http://www-cs-students.stanford.edu/~silver/gae.html">don’t agree</a> and I might change my opinion in 3 month or so after having seen CC run inside GAE for a while, but for now my first experience with google app engine was pretty pleasant.<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2011/04/12/experience-with-google-app-engine-spring-mvc-and-flex/613/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ruler Spark Component using dynamic skin parts and custom GraphicElement</title>
		<link>http://www.hulstkamp.com/2010/10/08/ruler-spark-component-using-dynamic-skin-parts-and-custom-graphicelement/584</link>
		<comments>http://www.hulstkamp.com/2010/10/08/ruler-spark-component-using-dynamic-skin-parts-and-custom-graphicelement/584#comments</comments>
		<pubDate>Fri, 08 Oct 2010 09:11:58 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[FXG]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[GraphicElement]]></category>

		<category><![CDATA[skin parts]]></category>

		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=584</guid>
		<description><![CDATA[Here’s a first version of a simple Ruler component that takes some of the techniques discussed in the couple of previous post into account.
The ruler can be scaled down or up by holding CTRL/SHIFT while clicking and can be moved by holding the ALT-Key and keeping the mouse button pressed. When scaling an animation is [...]]]></description>
			<content:encoded><![CDATA[<p>Here’s a first version of a simple Ruler component that takes some of the techniques discussed in the couple of previous post into account.</p>
<p>The ruler can be scaled down or up by holding CTRL/SHIFT while clicking and can be moved by holding the ALT-Key and keeping the mouse button pressed. When scaling an animation is applied for smoother transitions. For the labels an array of Strings can be set, each one defining a division on the ruler. The number of subdivisions can be set as well</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHRulerComponent/AHRulerTest.html"><img src="http://www.hulstkamp.com/byard/flex4/AHRulerComponent/rulerComponent.png" alt="Spark Ruler Component" /></a></p>
<p>Simple <a href="http://www.hulstkamp.com/byard/flex4/AHRulerComponent/AHRulerTest.html">ruler component</a>. View source is enabled.</p>
<p><br/></p>
<h4>Custom GraphicElement to draw tick lines</h4>
<p>Instead of using and FXG-Path element a custom GraphicElement has been created to draw<span id="more-584"></span> the tick lines. This makes for a cleaner and more generic approach when drawing the ruler and reduces overhead when animation is applied while scaling.<br />
<br/></p>
<h4>Dynamic skin parts for the Labels</h4>
<p>For the labels dynamic skin parts are used. Here’s a little recap on how to work with dynamic skin parts.</p>
<ul>
<li>Declare a dynamic skin part in the Declarations segment of the skin. Wrap it up in a Component and give the component an id.</li>
<li>Declare the skin part in the component, referencing it via  id in the skin. The type is of mx.core.IFactory.</li>
<li>To create a dynamic skin part at runtime call <em>createDynamicPartInstance([id of skin part])</em> from the component. This will return an instance of the desired skin part.</li>
<li>In the component add this instance to the skin or a group within the skin.</li>
<li>Optionally add it to an array for dynamically created instances for easier housekeeping.</li>
<li>Any Listener is best added in partAdded() similar to adding behavior to static skin parts. When adding event listeners do not forget to remove them in partRemoved().</li>
<li>A dynamic skin part can be removed at runtime by calling <em>removeDynamicPartInstance([id of skin part], instance)</em>. You also need to manually remove the instance form the group you’ve added them.</li>
</ul>
<p>If you need more information on dynamic skin parts, check out <a href="http://www.adobe.com/devnet/flex/articles/dynamic_skin_parts.html">this great article</a> by Florian Fesseler.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/10/08/ruler-spark-component-using-dynamic-skin-parts-and-custom-graphicelement/584/feed</wfw:commentRss>
		</item>
		<item>
		<title>Inspecting and creating a custom Spark GraphicElement</title>
		<link>http://www.hulstkamp.com/2010/10/07/inspecting-and-creating-a-custom-spark-graphicelement/570</link>
		<comments>http://www.hulstkamp.com/2010/10/07/inspecting-and-creating-a-custom-spark-graphicelement/570#comments</comments>
		<pubDate>Thu, 07 Oct 2010 07:35:18 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[GraphicElement]]></category>

		<category><![CDATA[Layout]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[VisualElement]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=570</guid>
		<description><![CDATA[
Mobile Flex Apps are around the corner. Hence it might be a good thing to inspect some of the more light-weighted approaches of Flex to create visual elements and components that can take part in the Spark layout process. In this last example I had a look at SpriteVisualElement. 
Now, it&#8217;s time for the GraphicElement. [...]]]></description>
			<content:encoded><![CDATA[<p>
Mobile Flex Apps are around the corner. Hence it might be a good thing to inspect some of the more light-weighted approaches of Flex to create visual elements and components that can take part in the Spark layout process. In <a href="http://www.hulstkamp.com/2010/09/29/use-spritevisualelement-to-implement-a-simple-component-in-flex-4/555">this last example</a> I had a look at <em>SpriteVisualElement</em>. </p>
<p>Now, it&#8217;s time for the <em>GraphicElement</em>. </p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHFlowerGraphicElement/AHFlowerTest.html" alt="custom GraphicElement example"><img src="http://www.hulstkamp.com/byard/flex4/AHFlowerGraphicElement/flowerGraphicElement.png" alt="custom flower GraphicElement used in background" /><br />
</a><br />
<a href="http://www.hulstkamp.com/byard/flex4/AHFlowerGraphicElement/AHFlowerTest.html"">Example </a>using custom Graphic Elements. View source is enabled.</p>
<p>The <em>GraphicElement </em>and its subclasses are responsible to draw a significant amount of the Spark components graphics. FXG elements like <em>Rect</em>, <em>Path</em>, <em>Line </em>etc. all derive from <em>GraphicElement</em>.</p>
<p>A  <em>GraphicElement </em>is actually neither a <em>DisplayObject </em>nor does it offer any form of interaction. Its super class is the <em>EventDispatcher </em>and it uses an<span id="more-570"></span> internal DisplayObject to draw itself into. It does implement interfaces like <em>IVisualElement </em>and <em>IGraphicElement </em>and can therefore be laid out and displayed by Spark. </p>
<p>The internal display object used for drawing purposes is set and managed by Flex and multiple graphic elements can draw onto the same display object. Sharing display objects reduces overhead and in most cases leads to better performance. </p>
<p>This naturally has some implications which need to be considered when creating a custom GraphicElement</p>
<ul>
<li>A GraphicElement gets a DisplayObject to draw into and the display object might be shared. Both is managed by Flex.</li>
<li>If a GraphicElement needs to be redrawn all other graphic elements that share the same DisplayObject will need to redraw themselves.</li>
<li>If creating a custom GraphicElement which shares a display object with other graphic elements, make sure to not clear the graphics, as this would wipe out drawings that have formerly been made by other elements.</li>
<li>Properties that are applied to the DisplayObject will be reflected by all graphic elements that share the same display object. Thus, the use of individual filters, color transformations, rotation etc. require the GraphicElement to own its own display object. The standard implementation takes care of this.</li>
<li>Since GraphicElement is not a display object, we need to get a reference to the graphics object for drawing. We can get this reference form the drawnDisplayObject member.</li>
<li>When drawing, the offset of the graphic element relative to its display object has to be taken into account.</li>
</ul>
<p><br/></p>
<h4>Creating a custom GraphicElement</h4>
<p>
In most cases, there is no need to create a custom graphic element, as the FXG Path element can be used to draw most of the required paths. The FXG Path element takes a string of drawing commands, parses it and translates it to drawing commands that are applied to the display object.<br />
This is well suited for static paths, e.g. the ones that are exported by Illustrator or Catalyst. </p>
<p>On the other hand, if a parameterized path is required we would need to dynamically build a string of graphic commands and Flex would need to parse them again, leading to unnecessary overhead. In such a case it might be better to create a custom GraphicElement that has the required properties and a drawing routine which takes them into account.</p>
<p>UPDATE: For the FXG-Path building approach see <a href="http://coenraets.org/blog/2010/09/building-lightweight-mobile-ready-charts-with-fxg/#more-1188">the great lightweight charts</a> by Christophe Coenraets.</p>
<p>Creating a custom graphic element is straightforward, a few things must be considered though (see source in the example).</p>
<ul>
<li>Override the <em>updateDisplayList()</em> function to call the custom drawing routine, or the<em> draw()</em> function when using a StrokedElement or a FilledElement.</li>
<li>Get the graphics object from (drawnDisplayObject as Sprite).graphics.</li>
<li>Respect the coordinates of the GraphicElement relative to the one of its DisplayObject. The 	<em>drawX </em>and <em>drawY</em> properties of a GraphicElement store the required offset.</li>
<li>Inside the drawing function do not clear the graphics since the element might use a shared display object and this would clear out graphics that have been drawn by other graphic elements.</li>
<li>The GraphicElement class implements the <em>IInvalidating</em> interface and can therefore take part in the invalidation process. If a property is set that affects the drawing, call the required invalidation functions and do the update later in the validation pass.</li>
</ul>
<p><br/></p>
<h4>Managing shared display object</h4>
<p>
The management of display objects for any GraphicElement is done by Flex via the Group that owns the element. In most cases there is no need to care about this, but if required, Flex offers some ways to indicate if a shared DisplayObject is ok to use or if an own display object is needed.</p>
<ul>
<li>Use <em>needsDisplayObject()</em> to indicate if a GraphicElement needs his own display object. The default implementation checks if any properties are used that require an own display object (rotation, color transformation, belnd modes etc.). </li>
<li>Likewise <em>canShareWithNext()</em> and <em>canShareWithPrevious()</em> can be used to indicate if a GraphicElement can be drawn onto the same display object as the previous/next one in the queue.</li>
<li>It is tempting to use the property <em>displaySharingMode</em>. This does not work as expected, as Flex uses this property to manage the objects and values set manually will be overwritten.</li>
<li>If Flex needs to create a display object for a graphic element it calls its <em>createDisplayObject()</em> function. The default implementation returns an object of type <em>InvalidatingSprite</em> that implements the<em> ISharedDisplayObject</em> interface.</li>
</ul>
<p><br/></p>
<h4>Interactivity</h4>
<p>
The purpose of the GraphicElement is to draw and manage graphics in an optimized manner (by sharing display objects). It is not an interactive element, the element is embedded within a Spark container and interaction should be done at a higher level.</p>
<p>To enable interactivity on a graphic element directly, a couple of things need to be done, which in most cases is actually bad practice. However, since this post is about inspecting the GraphicElement, let’s still see what needs to be done do to get interaction on a graphic element.</p>
<p>As mentioned above, the GraphicElement uses a DisplayObject to draw its graphics. The DisplayObject used by a GraphicElement is an <em>InvalidatingSprite </em>(extends from Sprite) that has the <em>mouseEnabled </em>and <em>mouseChildren </em>properties set to false. To get interactivity in a way that makes sense, we’d need to enable interaction on the InvalidatingSprite and disable display object sharing, as we do not want interaction to be affected by other graphic elements that share the same display object.</p>
<p>To turn on interactivity and to make sure interaction is not shared with other elements, we will need to </p>
<ul>
<li>override the <em>createDisplayObject()</em> function and</li>
<li>set the <em>mouseEnbled </em>and <em>mouseChildren </em>properties of the returned DisplayObject to true</li>
<li>add any listeners to the DisplayObject</li>
<li>override <em>needsDisplayObject</em>() and return true</li>
<li>likewise override <em>canShareWithNext</em>() and <em>canShareWithPrevious</em>() and return false</li>
</ul>
<p>You’ll find the source code for this in the example. View source is enabled.</p>
<p>This of course undermines the attempt of Flex for optimization when drawing graphic elements. If interaction is needed directly on a custom graphic object it might be better to use a SpriteVisualElement that is in fact an interactive object. See <a href="http://www.hulstkamp.com/2010/09/29/use-spritevisualelement-to-implement-a-simple-component-in-flex-4/555">the example</a> of a ruler implemented as a SpriteVisualElelement.
</p>
<p><br/></p>
<h4>Conclusion</h4>
<p>The GraphicElement is Spark’s key class to do optimized drawing. If a parameterized path needs to be drawn that updates often, it might be a better choice to create a custom GraphicElement instead on relying on the FXG-Path element. Interactivity can be enforced but it is better to handle it on higher levels. If you need a really light weight visual element, that offers interaction and can still take part in the Spark layout process consider using SpriteVisualElement.</p>
<p>For more information on traversing GraphicElements (or IVisualElements in general) read <a href="http://www.billdwhite.com/wordpress/?p=296">this</a> excellent write-up by Bill White. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/10/07/inspecting-and-creating-a-custom-spark-graphicelement/570/feed</wfw:commentRss>
		</item>
		<item>
		<title>Flex Tab Key Navigation for custom Spark PopUp</title>
		<link>http://www.hulstkamp.com/2010/10/06/flex-tab-key-navigation-for-custom-spark-popup/593</link>
		<comments>http://www.hulstkamp.com/2010/10/06/flex-tab-key-navigation-for-custom-spark-popup/593#comments</comments>
		<pubDate>Wed, 06 Oct 2010 18:09:23 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[flex 4]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=593</guid>
		<description><![CDATA[This took me a while to figure out.
In a project I created a custom PopUp, nothing fancy, just a couple of text inputs. When I tried to enable Tab key navigation I set the required properties but Flex would simply ignore tab key navigation to the input fields in the pop up.
The Documentation about the [...]]]></description>
			<content:encoded><![CDATA[<p>This took me a while to figure out.</p>
<p>In a project I created a custom PopUp, nothing fancy, just a couple of text inputs. When I tried to enable Tab key navigation I set the required properties but Flex would simply ignore tab key navigation to the input fields in the pop up.</p>
<p>The Documentation about the IFocusManager states that a pop up will get its own FocusManager and its own tab loop.</p>
<p>After some tracing I found that my pop up and its child weren’t included in the FocusManager as focus objects. In fact, there was no FocusManager for my pop up at all.</p>
<p>The reason for this is that when the PopUpMangerImpl is about to create and configure the pop up, it checks if the pop up is a IFocusManagerContainer so that focus can be added.<span id="more-593"></span></p>
<p>Unfortunately my popup was a Group which does not implement the IFocusManagerContainer interface. Naturally no FocusManager would be created.</p>
<p>If you want to use a Spark Group as your pop up, the solution is to create a new class that extends from Group and implements the IFocusManagerContainer. Then use this class as the container for the pop up.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">.
.
.
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AHPopUpGroup <span style="color: #0066CC;">extends</span> Group <span style="color: #0066CC;">implements</span> IFocusManagerContainer
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AHPopUpGroup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 *  @private
		 *  Storage for the defaultButton property.
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _defaultButton:IFlexDisplayObject;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Inspectable<span style="color: #66cc66;">&#40;</span>category=<span style="color: #ff0000;">&quot;General&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 *  The Button control designated as the default button for the container.
		 *  When controls in the container have focus, pressing the
		 *  Enter key is the same as clicking this Button control.
		 *
		 *  @default null
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> defaultButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IFlexDisplayObject
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _defaultButton;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 *  @private
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> defaultButton<span style="color: #66cc66;">&#40;</span>value:IFlexDisplayObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_defaultButton = value;
			ContainerGlobals.<span style="color: #006600;">focusedContainer</span> = <span style="color: #000000; font-weight: bold;">null</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
.
.
.</pre></div></div>

<p>And the mxml for the pop up becomes something like this</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;">.
.
.
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #000000;">		Uses a Group that implements the IFocusManagerContainer</span>
<span style="color: #000000;">		--&gt;</span></span>
&nbsp;
			.
			.
			.
			TextInput, Buttons etc now get focus on tab key navigation
			.
			.
			.
&nbsp;
.
.
.</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/10/06/flex-tab-key-navigation-for-custom-spark-popup/593/feed</wfw:commentRss>
		</item>
		<item>
		<title>Use SpriteVisualElement to implement a simple component in Flex 4</title>
		<link>http://www.hulstkamp.com/2010/09/29/use-spritevisualelement-to-implement-a-simple-component-in-flex-4/555</link>
		<comments>http://www.hulstkamp.com/2010/09/29/use-spritevisualelement-to-implement-a-simple-component-in-flex-4/555#comments</comments>
		<pubDate>Wed, 29 Sep 2010 08:46:55 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[custom component]]></category>

		<category><![CDATA[flash sprite]]></category>

		<category><![CDATA[layout pass]]></category>

		<category><![CDATA[SpriteVisualElement]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=555</guid>
		<description><![CDATA[In Flex 4 the standard way to create a custom control is to extend from SkinnableComponent, then implement the handling and management of events and states there and use a separate skin class for the visual representation of the component.
A class that gets less attention, but might be useful in a couple of scenarios to [...]]]></description>
			<content:encoded><![CDATA[<p>In Flex 4 the standard way to create a custom control is to extend from SkinnableComponent, then implement the handling and management of events and states there and use a separate skin class for the visual representation of the component.</p>
<p>A class that gets less attention, but might be useful in a couple of scenarios to create a control alternatively, is the SpriteVisualElement class.</p>
<p>This example shows an implementation of a simple ruler by extending the SpriteVisualElement.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHRulerSpriteVisualElement/AHRulerTest.html"><img src="http://www.hulstkamp.com/byard/flex4/AHRulerSpriteVisualElement/Ruler.png" alt="Ruler implemented by extending SpriteVisualElement" /></a></p>
<h3>The SpriteVisualElement</h3>
<p>The SpriteVisualElement is a display object that can be used inside spark containers.</p>
<p>It inherits from Sprite and implements the <span id="more-555"></span>IVisualElement interface and can therefore take part in the spark layout process. This means, properties like height, width, top, right, bottom, left etc. can be used to lay out a SpriteVisualElement like an UIComponent.</p>
<p>As it inherits from Sprite you’ll get a reference to the Graphics object to draw onto and all the common events of a flash interactive object (mouse, gestures, focus etc.) - in other words, a flash sprite that can be used within the spark architecture.</p>
<p>The SpriteVisualElement is light-weight and might be the better choice to implement some interactive object if you can live without all the bells and whistles of the UIComponent. Less features, less overhead.</p>
<h3>Use inside the Flex layout pass</h3>
<p>Implementing the ruler is like coding a sprite in Flash but there’s a little additional work required to hook it up with the Spark layout pass.</p>
<p>During the layout pass Flex calls</p>
<ul>
<li> setLayoutBoundsSize(width:Number, height:Number, postLayoutTransform:Boolean=true)</li>
</ul>
<p>We can override this function to call our drawing function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setLayoutBoundsSize<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">height</span>:<span style="color: #0066CC;">Number</span>, postLayoutTransform:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">super</span>.<span style="color: #006600;">setLayoutBoundsSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">height</span>, postLayoutTransform<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//call our drawing function</span>
	draw<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The ruler has properties for the number of divisions and subdivisions. Both require an update to the graphics so we need to tell Flex about this. We can achieve this by calling</p>
<ul>
<li>invalidateParentSizeAndDisplayList()</li>
</ul>
<p>This will mark the parent component as invalid and will finally trigger a call to setLayoutBoundsSize on our object where we can redraw the graphics based on the updated values of the properties.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> divisions<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	_divisions = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, value<span style="color: #66cc66;">&#41;</span>;
	invalidateParentSizeAndDisplayList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Conclusion</h3>
<p>Depending on the requirements, you might want to - and usually do - use the full stack (SkinnableComponent/SparkSkin with nested components and FXG). Still, under some circumstances and regarding resources and performance, implementing a simple component as a SpriteVisualElement may be an option to be considered. Also note, a SpriteVisualElement can live within a spark container, thus you can add it to any skin and mix it up with FXG elements or Spark components.</p>
<p>Click <a href="http://www.hulstkamp.com/byard/flex4/AHRulerSpriteVisualElement/AHRulerTest.html">here</a> for the demo. View source is enabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/09/29/use-spritevisualelement-to-implement-a-simple-component-in-flex-4/555/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nicer Tooltips and balloon help for Flex 4</title>
		<link>http://www.hulstkamp.com/2010/05/30/nicer-tooltips-and-balloon-help-for-flex-4/525</link>
		<comments>http://www.hulstkamp.com/2010/05/30/nicer-tooltips-and-balloon-help-for-flex-4/525#comments</comments>
		<pubDate>Sun, 30 May 2010 17:22:43 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Sound]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[skin]]></category>

		<category><![CDATA[ToolTipManager]]></category>

		<category><![CDATA[tootlips]]></category>

		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=525</guid>
		<description><![CDATA[Tooltips are a good way to provide a user with additional information for controls and Flex offers Tooltips out of the box. The default Tooltips are fine but when text gets longer than just a few words usability may suffer.
For a current project, I needed more like a balloon help in place of tooltips and [...]]]></description>
			<content:encoded><![CDATA[<p>Tooltips are a good way to provide a user with additional information for controls and Flex offers Tooltips out of the box. The default Tooltips are fine but when text gets longer than just a few words usability may suffer.</p>
<p>For a current project, I needed more like a balloon help in place of tooltips and therefore decided not to use Flex default tooltips.</p>
<p>Regarding usability of the tooltips (balloon help) I want to be able to</p>
<ul>
<li>Display an optional tooltip title</li>
<li>Display formatted tooltip text</li>
<li>Display icons</li>
<li>Colorize the tooltip based on the semantic of the invoking control</li>
<li>Consistent Placement</li>
<li>Have all title, text, styles for the tooltips stored in a central location</li>
<li>Have the tooltips work in a generic and Flex-compliant way</li>
</ul>
<p>Flex gives you a few ways to customize tooltips from registering your custom ToolTip class to intercepting Tooltip events where you can hook up the custom tooltip. All of these approaches fall either short of the requirements I had or would add additional overhead so I simply created a custom ToolTipManager that would alter the behaviour of the default ToolTipManager.</p>
<p>Here&#8217;s a <a href="http://www.hulstkamp.com/byard/flex4/AHNiceToolTip/Flex4NiceTooltips.html">demo </a>of the final result, the approch is described further down.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHNiceToolTip/Flex4NiceTooltips.html"><br />
<img src="http://www.hulstkamp.com/byard/flex4/AHNiceToolTip/NiceToolTips.png" alt="NiceToolTips Demo" /><br />
</a></p>
<p>Since I like to have all resources centralized, the approach I followed was to <span id="more-525"></span>interpret the value of the <em>tooltip</em>- or the <em>errorString </em>property on a control not as the tooltip text to display but as a partial key to lookup title, text, styles etc. in a resource bundle. Form this partial key concrete keys would be derived to lookup the values for a controls tooltip.</p>
<p>For example</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=”OK” tooltip=”ToolTipBundle.okButton” <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>would point to the ResourceBundle named  ‘<em>ToolTipBundle</em>’ and within this to all entries of a key starting with <em>tooltip.okButton</em>. Then the values for title, text etc. will be looked up by the custom ToolTipManager implementation and be applied to the tooltip.</p>
<p>The first token in the tooltip property specifies the name of the resource bundle, the second token the partial key for looking up the entries in the resource bundle. If no second token is specified the id (if any) of the component is being used.</p>
<p>Entries in the resource bundle then refer to the partial key submitted and define the concrete values to use for the tooltip.</p>

<div class="wp_syntax"><div class="code"><pre class="properties" style="font-family:monospace;">tooltip.okButton.title=Title of Tooltip
tooltip.okButton.text=Text for this tooltip
tooltip.okButton.styleName=CSS class to use for this tooltip
tooltip.okButton.placement=bottomRight|bottomLeft|topRight|topLeft
tooltip.okButton.color=Color of text
tooltip.okButton.chromeColor=Color of tooltip</pre></div></div>

<p>Color and chromeColor are there for convenience but can also be set via the CSS class specified by styleName. If any of the entries are not specified fallbacks to default values are used.</p>
<p>To make this work some methods of the default ToolTipManager need to be overwritten</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">override mx_internal <span style="color: #000000; font-weight: bold;">function</span> initializeTip<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>

<p>This is where the cstom implementation looks up the values and assigns them to the tooltip.</p>
<p>Additionally there’s the</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">override mx_internal <span style="color: #000000; font-weight: bold;">function</span> positionTip<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>

<p>method to position the tooltip in a custom way.</p>
<p>The custom ToolTipManager implementation is registered at loading using a custom preloader class.</p>
<p>The custom Tooltip itself  is a simple SkinnableComponent associated with a SparkSkin. There’s a required skin part for the text and a dynamic skin part for the label that only gets added if any value for a title  is provided.</p>
<p>For both title and text a RichText component is used within the skin so that formatting the text in a rich way is possible. The associated skin is then responsible to draw the tooltip based on the provided placement.<br />
Having set this up, usage of the custom tooltips for any app is simple.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span>               </span>
<span style="color: #000000;">    preloader=<span style="color: #ff0000;">&quot;com.hulstkamp.flex.spark.preloaders.CustomMixinPreloader&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>This will register the custom ToolTipManager.</p>
<p>For additional documentation see the source in the demo (view source is enabled).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/05/30/nicer-tooltips-and-balloon-help-for-flex-4/525/feed</wfw:commentRss>
		</item>
		<item>
		<title>Updated components to Flex 4 sdk final</title>
		<link>http://www.hulstkamp.com/2010/05/08/updated-components-to-flex-4-sdk-final/506</link>
		<comments>http://www.hulstkamp.com/2010/05/08/updated-components-to-flex-4-sdk-final/506#comments</comments>
		<pubDate>Sat, 08 May 2010 16:26:43 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[custom component]]></category>

		<category><![CDATA[release sdk]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=506</guid>
		<description><![CDATA[During the past year I&#8217;ve posted a couple of custom Gumbo (flex 4 beta) components and skins.
Since they&#8217;ve been built on beta sdks, these components might need some adjustments to work with the Flex 4 release sdk.
To save you the work of figuring out what to adjust here are the most requested components updated to [...]]]></description>
			<content:encoded><![CDATA[<p>During the past year I&#8217;ve posted a couple of custom Gumbo (flex 4 beta) components and skins.</p>
<p>Since they&#8217;ve been built on beta sdks, these components might need some adjustments to work with the Flex 4 release sdk.</p>
<p>To save you the work of figuring out what to adjust here are the most requested components updated to Flex 4 release sdk. Click on the images, view source is enabled.</p>
<p>Flex 4 Spark Rating Component. View source enabled. Original post <a href="http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464">here</a>.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHCityRating/AHPopUpAnchorTest.html"><img title="Flex 4 Spark Rating Component" src="http://www.hulstkamp.com/byard/assets/images/cityRatingComponent.png" alt="Flex 4 Spark Rating Component" width="456" height="303" /></a></p>
<p>Flex 4 Spark Icon Button based on a generic skin.View source enabled. Original post <a href="http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439">here</a>.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHGenericFxgIconButtonTest/AHFXGIconTest.html"><img title="Flex 4 Spark Icon Button based on a generic skin" src="http://www.hulstkamp.com/byard/assets/images/GenericFXGIconButtons.png" alt="Flex 4 Spark Icon Button based on a generic skin" width="512" height="193" /></a></p>
<p>Flex 4 Spark icon button. View source enabled.Original post <a href="http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403">here</a>.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHIconButtonTest/AHSimpleIconButtonTest.html"><img title="Flex 4 Spark Icon Button" src="http://www.hulstkamp.com/byard/assets/images/iconButtons.png" alt="Flex 4 Spark Icon Button" width="345" height="124" /></a></p>
<p>Flex 4 Spark custom checkbox. View source enabled. Original post <a href="http://www.hulstkamp.com/2009/06/13/custom-spark-checkbox-component-in-flex-4-gumbo/361">here</a>.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHCheckBoxTest/AHCheckboxTest.html"><img title="Flex 4 Spark custom checkbox" src="http://www.hulstkamp.com/byard/assets/images/CustomCheckBox.png" alt="Flex 4 Spark custom checkbox" width="339" height="169" /></a></p>
<p>Flex 4 Spark custom knob button. View source enabled. Original post <a href="http://www.hulstkamp.com/2009/02/26/custom-component-in-flex-4-gumbo-a-knob-button-part-1/300">here</a>.</p>
<p><a href="http://www.hulstkamp.com/byard/flex4/AHFxgKnobButtonTest/AhFxButtonTest.html"><img title="Flex 4 Spark custom knob button" src="http://www.hulstkamp.com/byard/assets/images/CustomKnobComponent.png" alt="Flex 4 Spark custom knob button" width="480" height="130" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/05/08/updated-components-to-flex-4-sdk-final/506/feed</wfw:commentRss>
		</item>
		<item>
		<title>Flex 4: change baseColor to chromeColor and useChromeColor=true</title>
		<link>http://www.hulstkamp.com/2010/04/07/flex-4-change-basecolor-to-chromecolor-and-usechromecolortrue/496</link>
		<comments>http://www.hulstkamp.com/2010/04/07/flex-4-change-basecolor-to-chromecolor-and-usechromecolortrue/496#comments</comments>
		<pubDate>Wed, 07 Apr 2010 17:18:51 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[baseColor]]></category>

		<category><![CDATA[chromeColor]]></category>

		<category><![CDATA[colorization]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[styles]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=496</guid>
		<description><![CDATA[While updating the Gumbo-Components on this blog to flex 4 final I noticed that the style-property baseColor has been changed to chromeColor.
In addition to this the flag useChromeColor can be set to tell the SparkSkin to use chromeColor for colorization. For custom skins this can be set by overriding initializationComplete() in the skin.

override protected function [...]]]></description>
			<content:encoded><![CDATA[<p>While updating the Gumbo-Components on this blog to flex 4 final I noticed that the style-property <em>baseColor </em>has been changed to <em>chromeColor</em>.</p>
<p>In addition to this the flag <em>useChromeColor </em>can be set to tell the SparkSkin to use <em>chromeColor </em>for colorization. For custom skins this can be set by overriding <em>initializationComplete()</em> in the skin.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;">override protected <span style="color: #000000; font-weight: bold;">function</span> initializationComplete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>  <span style="color: #66cc66;">&#123;</span>
&nbsp;
	useChromeColor = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #0066CC;">super</span>.<span style="color: #006600;">initializationComplete</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Internally Flex checks this flag in <em>updateDisplayList()</em> of a <em>SparkSkin </em>and uses the value in chromeColor for colorization (respecting exclusions in get colorizeExclusions()).</p>
<p>If you are using Gumbo-Components from this blog that use baseColor be sure to make these adjustments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2010/04/07/flex-4-change-basecolor-to-chromecolor-and-usechromecolortrue/496/feed</wfw:commentRss>
		</item>
		<item>
		<title>Custom PopUp Rating Component in Spark Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464</link>
		<comments>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464#comments</comments>
		<pubDate>Thu, 09 Jul 2009 08:12:08 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[custom component]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[masking]]></category>

		<category><![CDATA[popup]]></category>

		<category><![CDATA[rating]]></category>

		<category><![CDATA[skin parts]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[states]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=464</guid>
		<description><![CDATA[I was experimenting a little with the PopUpAnchor in Spark Flex 4 and came up with a new custom component for ratings. The new component has the following characteristics:

Show a placeholder-icon that reflects the current rating and serves as an interactive element to open the ratings
ratings pop up for adjustment
both the placeholder-icon and the ratings-icons [...]]]></description>
			<content:encoded><![CDATA[<p>I was experimenting a little with the PopUpAnchor in Spark Flex 4 and came up with a new custom component for ratings. The new component has the following characteristics:</p>
<ul>
<li>Show a placeholder-icon that reflects the current rating and serves as an interactive element to open the ratings</li>
<li>ratings pop up for adjustment</li>
<li>both the placeholder-icon and the ratings-icons will be gradually filled with color when adjustments are being made</li>
<li>the icons are defined in FXG</li>
<li>the icons are not defined in the skin but can be passed as a style for generic use (one skin for different icons and ratings)</li>
<li>there is colorization of the icons based on styles</li>
<li>smooth transitions when opening the ratings</li>
</ul>
<p><a href="http://www.hulstkamp.com/byard/gumbo/cityRating/AHPopUpAnchorTest.html">Here&#8217;s a pseudo city-rating demo</a> that shows variations of the component using different icons and color settings for different ratings.</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/cityRating/AHPopUpAnchorTest.html"><img src="http://www.hulstkamp.com/byard/gumbo/cityRating/cityRatingComponent.png" alt="City Rating Component" /></a></p>
<p>You&#8217;ll find the source at the end of this post. It is <span id="more-464"></span>fully documented but here&#8217;s an overview of the key-concept nonetheless.</p>
<h3>Skin-Parts</h3>
<p>There are skin-parts for the open-button (which is actually a group that works as a button), the drop-down which is a group that holds the entire pop-up, the active-group and the passive-group that hold the icons for adjustments of the rating and the label-element to show the rating as text.</p>
<h3>Building the View</h3>
<p>The icons are not part of the skin. They will be set at run time and are pushed down to the skin when the component loads the different skin-parts.</p>
<p>In partAdded() of the component, the active-group and the passive-group are filled with the icons. Five icons in a colorized version are pushed down to the active part.  Five default icons are pushed down to the passive-group.</p>
<h3>Masking and Fill Effect</h3>
<p>To create an effect that gives the impression of gradually filling the icons when the rating is adjusted, masks are used.  When skin-parts are loaded, the component applies a mask to the active-group.  When the mouse is dragged to adjust the rating, the width of the mask is updated and the (colorized) icons of the active-group are revealed.</p>
<p>The mask is not part of the skin. It is created at run-time by the component and applied to the relevant skin-part.</p>
<h3>FXG Icons passed via Styles</h3>
<p>The Icons are defined in FXG. Basically each Icon is a MXML-Component. The Icons are passed as a ClassReference to the component via styles. The ClassReference is then used to create an instance of this class at run-time. The instances of the icon are then added to their respective groups.<br />
An Icon is basically a mxml-component that extends from Group. You can create your own and reference it via the rating Icon style.</p>
<h3>Colorization based on Styles</h3>
<p>The Icons are colorized at run-time. Based on some colors that are passed as styles the icons get colorized using a ColorTransform.</p>
<h3>Effects on PopUp</h3>
<p>There is a resize and a fade effect when the pop up is openend. These are defined on the skin - you can remove them by simply commenting out the transition part in the skin.</p>
<h3>Separation of Concerns</h3>
<p>Spark promotes a clean separation of concerns. The Component should keep track of the data/state and work as a controller, the skin is there for the view.  I decided to create and update the mask in the component, because the masking effect is an inherent part of this implementation and setting up the masking infrastructure in the component helps to keep the skin cleaner. Another approach would be to define the mask in the skin, then pull the value for the rating from the component and adjust the mask accordingly.<br />
Still, every aspect of the look (gap, background-colors, borders, effects etc.) is controlled by the skin.</p>
<h3>Usage</h3>
<p>Setting the basic styles for the AHPopUpRatingComponent:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">ah|AHPopUpRatingComponent <span style="color: #00AA00;">&#123;</span>
	skinClass<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'AHPopUpRatingComponentSkin'</span><span style="color: #00AA00;">&#41;</span>;
	passiveIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x808080&quot;</span>;
	activeIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xc0c0c0&quot;</span>;
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xb0b0b0&quot;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Using a variation of style values: For this example use styleName=&#8217;medicareRating&#8217; on the component to set the css-class. It uses the Icon under myLibrary.HealthCross and has a light blue color for the active icons.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">ah|AHPopUpRatingComponent<span style="color: #6666ff;">.medicareRating</span> <span style="color: #00AA00;">&#123;</span>
	ratingIcon<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'myLibrary.HealthCross'</span><span style="color: #00AA00;">&#41;</span>;
	activeIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xCAEAFF&quot;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The icons are mxml-components, that extend from Group. Use the fully qualified class-path in the ClassReference of the ratingIcon-style to reference the icon. Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;25&quot;</span> height=<span style="color: #ff0000;">&quot;25&quot;</span>  xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Path</span>  x=<span style="color: #ff0000;">&quot;5&quot;</span> winding=<span style="color: #ff0000;">&quot;nonZero&quot;</span> ai:knockout=<span style="color: #ff0000;">&quot;0&quot;</span> data=<span style="color: #ff0000;">&quot;M 9.404 0.01 C 9.051 8.355 -1.506 9.232 3.065 16.324 C 1.835 17.4 0.006 19.866 0.006 25.01 L 1.886 25.01 C 1.886 20.554 3.357 18.569 4.244 17.776 C 18.309 18.361 13.558 4.163 9.404 0.01 Z&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:LinearGradient</span> x=<span style="color: #ff0000;">&quot;6.82861&quot;</span> y=<span style="color: #ff0000;">&quot;0.00683594&quot;</span> scaleX=<span style="color: #ff0000;">&quot;25&quot;</span> rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xfbfbfb&quot;</span> ratio=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xdcdcdc&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xcccccc&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0x909090&quot;</span> ratio=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:LinearGradient</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColorStroke</span> color=<span style="color: #ff0000;">&quot;0xd8d8d8&quot;</span> caps=<span style="color: #ff0000;">&quot;none&quot;</span> weight=<span style="color: #ff0000;">&quot;1&quot;</span> joints=<span style="color: #ff0000;">&quot;miter&quot;</span> miterLimit=<span style="color: #ff0000;">&quot;4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Path</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p><del datetime="2010-05-08T16:38:25+00:00">Get the source (sdk: 7282) <a href="http://www.hulstkamp.com/byard/gumbo/cityRating/srcview/index.html">here</a>.</del></p>
<p>Source <a href="http://www.hulstkamp.com/2010/05/08/updated-components-to-flex-4-sdk-final/506">updated </a>to release sdk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464/feed</wfw:commentRss>
		</item>
		<item>
		<title>Advanced FXG Spark Icon Buttons with one generic skin in Flex4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439</link>
		<comments>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439#comments</comments>
		<pubDate>Sat, 20 Jun 2009 17:49:25 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[generic]]></category>

		<category><![CDATA[Icons]]></category>

		<category><![CDATA[pseudo selectors]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[states]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=439</guid>
		<description><![CDATA[For the past couple of days I&#8217;ve had a look at creating Spark Icon Buttons. In this post I&#8217;ve created an FXG Icon Button with some transitions, leveraging pseudo selectors for states. The Icon was &#8216;hardcoded&#8217; into the skin. For another Icon I would need to duplicate the skin and introduce another graphic. Not exactly [...]]]></description>
			<content:encoded><![CDATA[<p>For the past couple of days I&#8217;ve had a look at creating Spark Icon Buttons. In <a href="http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403">this post</a> I&#8217;ve created an FXG Icon Button with some transitions, leveraging pseudo selectors for states. The Icon was &#8216;hardcoded&#8217; into the skin. For another Icon I would need to duplicate the skin and introduce another graphic. Not exactly generic. There are <a href="http://www.hulstkamp.com/?p=433">other ways</a> to bring graphics into Spark Skins but none of them work with FXG Elements directly.</p>
<p>What I want is:</p>
<ul>
<li>work with FXG Graphic Elements for simpler manipulation and scaling</li>
<li>easily export the FXG-Definitions for the icons from a tool and/or be able to change them in FB directly</li>
<li>colorize the icons based on a color style-property and do this per state</li>
<li>change the icons based on a style-property and do this per state</li>
<li>change icons at runtime</li>
<li>scaling effect on icon</li>
<li>have ONE generic skin, so no duplicates for different icons are necessary</li>
</ul>
<p>Most of the trouble with generic skins comes from the fact that there is no way to access the FXG Library-Definitions at run-time  (as far as I know) - like getting an instance of a symbol in the library, the way we had in flash. Here&#8217;s a <a href="http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337">hack</a> but I&#8217;d rather not use it.</p>
<p>After some headaches I finally managed to get a solution I can live with:</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/AHFXGIconTest.html"><img class="alignnone" title="Generic FXG Icon Buttons" src="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/GenericFXGIconButtons.png" alt="" width="512" height="193" /></a></p>
<p>Click <a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/AHFXGIconTest.html">here</a> for a test.</p>
<p>You&#8217;ll find the source at the end of this post.</p>
<p>The solution regarding the work flow mainly comes down to<span id="more-439"></span></p>
<ul>
<li>Create Icons in Illustrator and convert them to symbols. One symbol per icon, name them. Save from Illustrator as ai.</li>
<li>Load the Illustrator-File in Flash Catalyst and go to the Code-View</li>
<li>You&#8217;ll see that FC creates mxml-files with the graphical content per icon</li>
<li>Copy these files over to Flex-Builder or set the source path so that the catalyst export is in your flex project</li>
</ul>
<p>In the code there are some key concepts:</p>
<ul>
<li>In the skin there is a group where the icons will get attached at run time</li>
<li>The skin listens for state changes and creates an instance of an icon component based on the iconName that is passed via styles.</li>
<li>There is some caching involved, so that there will be no instantiation when an icon/state has allready been created</li>
<li>The Icons get colorized based on a style property and - if defined  - per state.</li>
<li>The colorization occurs recursively, diving through the nested elements and setting the color of any nested FilledElement</li>
<li>There is some code involved that manages the scaling of the new instances for the transitions</li>
<li>Icons, colors and baseColors can be set via styles (and using pseudo selectors for over and down states)</li>
</ul>
<p><del datetime="2010-05-08T16:37:22+00:00">Here&#8217;s the <a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/srcview/index.html">source </a>(sdk 4.0.0.7282)</del></p>
<p>Source <a href="http://www.hulstkamp.com/2010/05/08/updated-components-to-flex-4-sdk-final/506">updated </a>to Flex 4 release sdk.</p>
<p>Note: As a variation to instantiate the icons you could put all the FXG-Definition in the Skin inside the library and create them at runtime using the hack mentioned at the beginning of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439/feed</wfw:commentRss>
		</item>
	</channel>
</rss>

