<?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>RIAstar</title>
	<atom:link href="http://blog.riastar.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.riastar.net</link>
	<description>Sex, drugs and rich internet applications</description>
	<lastBuildDate>Mon, 20 Feb 2012 13:19:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>RIA utilities: copying instance properties</title>
		<link>http://blog.riastar.net/development/flex-copy-instance-properties/</link>
		<comments>http://blog.riastar.net/development/flex-copy-instance-properties/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 21:38:00 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[introspection]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=73</guid>
		<description><![CDATA[I&#8217;ve lost count on how many times I&#8217;ve needed this in RIA development with Flex or ActionScript: the possibility to quickly copy property values from one class instance to another. The two most important uses I can think of right (&#8230;)</p><p><a href="http://blog.riastar.net/development/flex-copy-instance-properties/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve lost count on how many times I&#8217;ve needed this in RIA development with Flex or ActionScript: the possibility to quickly copy property values from one class instance to another. The two most important uses I can think of right now are these:</p>
<ul>
<li>You send a value object (VO) to the server. It comes back with a bunch of additional data. So far so good. But what you get back is another instance than the one you&#8217;ve just sent up the wire. Since the original instance may already be referenced somewhere in the application we do not want to simply replace it. We want the original instance filled with the new property values.</li>
<li>You show the user a form with which he can edit a VO. After he&#8217;s changed some values he can either commit his changes (&#8216;OK&#8217; button) or discard them (&#8216;cancel&#8217; button). In this scenario you&#8217;ll usually keep a copy of the original VO somewhere handy because you want to be able to restore it when needed. Now the story is the same as the previous one: we want to restore the values of the original instance, not replace it entirely.</li>
</ul>
<p>So I finally made this convenience method that uses <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#describeType%28%29" title="describeType() global function" target="_blank">describeType()</a> for introspection as an addition to my ObjectUtil class:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;height:400px;"><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 />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> copyProperties<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">source</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//copy properties declared in Class definition</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> sourceInfo<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = <span style="color: #004993;">describeType</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> propertyLists<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sourceInfo<span style="color: #000066; font-weight: bold;">.</span>variable<span style="color: #000066; font-weight: bold;">,</span> sourceInfo<span style="color: #000066; font-weight: bold;">.</span>accessor<br />
&nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> propertyList<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xmllist%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xmllist.html"><span style="color: #004993;">XMLList</span></a> <span style="color: #0033ff; font-weight: bold;">in</span> propertyLists<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> property<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> <span style="color: #0033ff; font-weight: bold;">in</span> propertyList<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>property<span style="color: #000066; font-weight: bold;">.</span>@access == <span style="color: #0033ff; font-weight: bold;">undefined</span> <span style="color: #000066; font-weight: bold;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property<span style="color: #000066; font-weight: bold;">.</span>@access == <span style="color: #990000;">&quot;readwrite&quot;</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = property<span style="color: #000066; font-weight: bold;">.</span>@<span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">target</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span> = <span style="color: #004993;">source</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//copy dynamic properties</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> <span style="color: #0033ff; font-weight: bold;">in</span> <span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">target</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span> = <span style="color: #004993;">source</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>I have needed this so many times I find it hard to fathom why something similar is not included in the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/ObjectUtil.html" title="mx.utils.ObjectUtil" target="_blank">mx.utils.ObjectUtil class</a>. It marries perfectly with <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/ObjectUtil.html#clone%28%29" title="ObjectUtil.clone() method" target="_blank">ObjectUtils.clone()</a>.</p>
<p>A simple example:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> editableItem<span style="color: #000066; font-weight: bold;">:</span>MyClass = ObjectUtil<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span>originalItem<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">//the user edits editableItem</span><br />
<span style="color: #009900; font-style: italic;">//if he cancels we just discard this instance</span><br />
<span style="color: #009900; font-style: italic;">//if he commits his changes we copy the new values</span><br />
ObjectUtil<span style="color: #000066; font-weight: bold;">.</span>copyProperties<span style="color: #000000;">&#40;</span>editableItem<span style="color: #000066; font-weight: bold;">,</span> originalItem<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/development/flex-copy-instance-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gigs &#8211; Easier ActionScript event handling &#8211; Protection revisited</title>
		<link>http://blog.riastar.net/development/gigs-easier-actionscript-event-handling-protection-revisited/</link>
		<comments>http://blog.riastar.net/development/gigs-easier-actionscript-event-handling-protection-revisited/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 12:07:06 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Gigs]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[Protection]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=67</guid>
		<description><![CDATA[Some time ago I created Protection. It was a library intended to help me write more readable ActionScript code without breaking out of the paradigms that were set out by Adobe. You can find a more thorough explanation and motivation (&#8230;)</p><p><a href="http://blog.riastar.net/development/gigs-easier-actionscript-event-handling-protection-revisited/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Some time ago I created Protection. It was a library intended to help me write more readable ActionScript code without breaking out of the paradigms that were set out by Adobe. You can find a more thorough explanation and motivation in <a href="http://blog.riastar.net/development/protection-actionscript-guarding/" title="Protection – an ActionScript guarding library">an article I wrote earlier this year</a>. I have been using it a lot now and as much as I like the basic idea, I came to realise that I had made a few wrong decisions. Most importantly:</p>
<ul>
<li><em>overcomplicated nomenclature</em>: in a silly attempt at originality I used military metaphors throughout the library (Sentries, Captains, Spies, etc.). These names make the code actually less transparent to someone who doesn&#8217;t know where they originated (i.e. anyone but me). This is in clear violation with my original intent: more readable code.</li>
<li><em>too many optional arguments</em>: a lot of different configuration was passed through one method with a bunch of optional arguments. Again, this would not be transparent to someone who read such code for the first time.</li>
<li><em>used inheritance (instead of composition)</em> to add the functionality to custom components</li>
<li><em>string-based conditionals</em>: <code class="codecolorer actionscript3 default"><span class="actionscript3"><span style="color: #990000;">&quot;r:propertyA&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;f:propertyB&quot;</span></span></code> to pass &#8216;propertyA&#8217; to the result handler and &#8216;propertyB&#8217; to the failure handler? Not so pretty.
</ul>
<p><strong>Enter Gigs</strong> (a.k.a RIAstar events)</p>
<p>So I decided to rethink the whole thing. To start with, the library name will remain my only attempt at originality. But let&#8217;s get down to the real stuff. This is how you use Gigs for tracking native Events:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">follow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>by<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span>submit<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> submit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//do some submitting</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>You can also join a &#8216;gigs.properties&#8217; file to the application in which you can associate default event types to specific classes. For instance 95% of the time on Buttons we listen for CLICK events. So we register a default for that:</p>
<div class="codecolorer-container properties twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="properties codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080; font-weight:bold;">spark.components.supportClasses.ButtonBase</span> <span style="color: #000000;">=</span><span style="color: #008000; font-weight:bold;"> click</span></div></div>
<p>And then we can write the following to do the same thing as before:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">follow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span>submit<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">//we can still explicitely listen for </span><br />
<span style="color: #009900; font-style: italic;">//another event than the registered default</span><br />
follow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>by<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span><span style="color: #004993;">startDrag</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p><strong>Passing property values</strong></p>
<p>The &#8216;handle&#8217; method takes one additional &#8230;rest argument to which you can pass all the event properties you want pass to the result handler. For example (I&#8217;ve registered the ListBase class with the IndexChangeEvent.CHANGE event type):</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">follow<span style="color: #000000;">&#40;</span>itemList<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span>editItemAt<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;newIndex&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> editItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">//open item editor</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p><strong>Unfollowing</strong> (a.k.a. removing event listeners)</p>
<p>There are three ways to stop following Events.</p>
<p>Very specifically:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">unfollow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>by<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span>submit<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Somewhat specifically (this will remove all event handlers that react to a CLICK event):</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">unfollow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>by<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>all<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Loose cannon (removes all event listeners for all event types for the given IEventDispatcher):</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">unfollow<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>all<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p><strong>To be continued</strong></p>
<p>That&#8217;s it for now. I have yet to recreate all functionality that existed in Protection, but I will hopefully get to that soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/development/gigs-easier-actionscript-event-handling-protection-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CFInvoke with a custom endpoint &#8211; ColdFusion</title>
		<link>http://blog.riastar.net/development/cfinvoke-custom-endpoint/</link>
		<comments>http://blog.riastar.net/development/cfinvoke-custom-endpoint/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 11:03:52 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[web-service]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=55</guid>
		<description><![CDATA[Consuming web services in ColdFusion is easy &#8211; at least since CF9, because it used to be a PITA in previous versions for some kinds of services (e.g. SOAP). You can even write it in one line &#8211; woohoo! -, (&#8230;)</p><p><a href="http://blog.riastar.net/development/cfinvoke-custom-endpoint/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Consuming web services in ColdFusion is easy &#8211; at least since CF9, because it used to be a PITA in previous versions for some kinds of services (e.g. SOAP).</p>
<p>You can even write it in one line &#8211; woohoo! -, like this:</p>
<div class="codecolorer-container cfm twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="cfm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfinvoke</span> webservice<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;http://www.riastar.net/service/?wsdl&quot;</span> </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;remoteMethodName&quot;</span> someArgument<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;hello&quot;</span> </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnvariable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;result&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></div></div>
<p><a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0a.html" title="CFInvoke docs" target="_blank">CFInvoke</a> assumes that the url of the service and its endpoint are the same. As usual with ColdFusion, this is all very nice and handy as long as your situation matches the default. But from the moment you have to customize a bit, you can start pulling out your hair. And the fact is that the real world has this tendency <em>not</em> to match the default situation.</p>
<p>For example: if the service you want to access has an endpoint that differs from the service url, you&#8217;re out of luck. I found the following &#8211; completely undocumented &#8211; solution to use a custom endpoint:</p>
<div class="codecolorer-container cfm twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="cfm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> service <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span></span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;webservice&quot;</span>, </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;http://www.riastar.net/service/?wsdl&quot;</span></span><br />
<span style="color: #333333;"><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span><br />
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> service._setProperty<span style="color: #0000FF;">&#40;</span></span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;javax.xml.rpc.service.endpoint.address&quot;</span>, </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;http://www.riastar.net/service&quot;</span></span><br />
<span style="color: #333333;"><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span><br />
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfinvoke</span> webservice<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#service#&quot;</span> </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;remoteMethodName&quot;</span> someArgument<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;hello&quot;</span> </span><br />
<span style="color: #333333;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnvariable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;result&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></div></div>
<p>Notice the underscore? That means you should probably not be using this.</p>
<p>Anyway, while researching this I also figured out the cfscript syntax to do the same thing.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service <span style="color: #339933;">=</span> createObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;webservice&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #3366CC;">&quot;http://www.riastar.net/service/?wsdl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
service._setProperty<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;javax.xml.rpc.service.endpoint.address&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #3366CC;">&quot;http://www.riastar.net/service&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
result <span style="color: #339933;">=</span> service.<span style="color: #660066;">remoteMethodName</span><span style="color: #009900;">&#40;</span>someArgument<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;hello&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><img src="http://blog.riastar.net/wp-content/uploads/2011/08/github.png" alt="" title="github" width="32" height="32" class="alignnone size-full wp-image-63" />You can also find this snippet on <a href="https://gist.github.com/1164657" title="CFInvoke endpoint Gist" target="_blank">Gist</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/development/cfinvoke-custom-endpoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protection &#8211; an ActionScript guarding library</title>
		<link>http://blog.riastar.net/development/protection-actionscript-guarding/</link>
		<comments>http://blog.riastar.net/development/protection-actionscript-guarding/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 23:13:43 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3Signals]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[Protection]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=41</guid>
		<description><![CDATA[I&#8217;ve just pushed a usable version of a new library &#8211; called Protection &#8211; to GitHub. It will enhance the handling of the computing flow of asynchronous programs in ActionScript 3 and make your code look cleaner. (You can use (&#8230;)</p><p><a href="http://blog.riastar.net/development/protection-actionscript-guarding/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just pushed a usable version of a new library &#8211; called <a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank">Protection</a> &#8211; to <a title="GitHub" href="https://github.com/" target="_blank">GitHub</a>. It will enhance the handling of the computing flow of asynchronous programs in ActionScript 3 and make your code look cleaner. (You can use it for synchronous programming too, but there&#8217;s less gain to be made.) At this stage it&#8217;s very much a work in progress, but the basic event handling is ready for production now. Next stop: enhancing service calls.</p>
<p><strong>This looks like something for me!</strong><br />
If you regularly look at your ActionScript code and find yourself mumbling: &#8220;<em>Ah, this class would look nice now, if it were not littered with all these &#8216;handleThisButtonClick&#8217;s and &#8216;handleThatLoadComplete&#8217;s. And then half of them take an &#8216;<a title="flash.events.Event" href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html" target="_blank">Event</a>&#8216; argument that is never even used in the function. Yuck!</em>&#8220;, <a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank">Protection</a> might be just up your alley.</p>
<p><strong>Don&#8217;t mention the war!</strong><br />
If you want your code to be checked as much as possible at compile time and you like to have all your variables nicely typed, please step away from this page. The idea for <a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank">Protection</a> came to me when I first started mucking around with <a title="Ruby" href="http://www.ruby-lang.org" target="_blank">Ruby</a>, so be warned.</p>
<p><strong>So what&#8217;s wrong with my current code?</strong><br />
Let&#8217;s have a look at a classic example (warning: I&#8217;m going to oversimplify things here for clarity&#8217;s sake). Consider the following component:</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 228px"><a href="http://blog.riastar.net/wp-content/uploads/2011/08/protection-example-simple-form.jpg"><img class="size-full wp-image-42 " title="protection example - a simple form" src="http://blog.riastar.net/wp-content/uploads/2011/08/protection-example-simple-form.jpg" alt="a simple form" width="218" height="85" /></a><p class="wp-caption-text">A simple form</p></div>
<p style="text-align: left;">It will have to do three things (all pretty straightforward, you may skip ahead):</p>
<ul>
<li>if you click the &#8216;reset&#8217; button,  the input field shall be emptied</li>
<li>if you click the &#8216;submit&#8217; button the content of the form is validated (i.e. there must be something in the input field and it must be formatted as an email address):
<ul>
<li>if the form is valid, your email address will be stored on my server, so I can spam you</li>
<li>if it is not, the form will display an error message and invite you to correct it</li>
</ul>
</li>
</ul>
<p>If you&#8217;re not a very good programmer your code might look somewhat like this:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;height:400px;"><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 />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> From <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> mailInput<span style="color: #000066; font-weight: bold;">:</span>TextInput<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> submitButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> resetButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span> <span style="color: #009900; font-style: italic;">//create the visual elements</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; submitButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> handleSubmitButtonClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resetButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> handleResetButtonClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> handleSubmitButtonClick<span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> isValid<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span> <span style="color: #009900; font-style: italic;">//do the validation of the form </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//and set local variable isValid</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isValid<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span> <span style="color: #009900; font-style: italic;">//send info to the server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span> <span style="color: #009900; font-style: italic;">//alert the user about his mistake</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Many people would encapsulate the validation part into its own method. I&#8217;ve encountered the resulting pattern many, many times in ActionScript code I&#8217;ve seen. There&#8217;s obviously still too much going on for one function to handle, so some developers decide to encapsulate the two cases each into their own function. This would result in:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><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 /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339966; font-weight: bold;">function</span> handleSubmitButtonClick<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isValid<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sendInfoToServer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; displayErrorMessages<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now you have three distinct functions. Each one of them does only one thing and it is very clear from its name what it is that it does exactly.</p>
<p>Much better!</p>
<p>And yet, I feel sad when I look at this. Because there is one ugly duckling in this class who&#8217;s name doesn&#8217;t give me the faintest clue of what it does. It only tells me <em>when</em> it will be called, which is frankly useless. And to top things off, it requires a parameter that it doesn&#8217;t even really need. Which &#8211; besides just being confusing &#8211; makes it impossible for me to call that function directly.</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 284px"><a href="http://blog.riastar.net/wp-content/uploads/2011/08/protection-form-outline.jpg"><img class="size-full wp-image-45" title="Form class outline" src="http://blog.riastar.net/wp-content/uploads/2011/08/protection-form-outline.jpg" alt="Form class outline" width="274" height="192" /></a><p class="wp-caption-text">The form class outline</p></div>
<p>This example is but a small component that does very little. Most classes in ActionScript are riddled with these kind of handlers.</p>
<p><strong>Enter Protection</strong><br />
Let me just rewrite 2 lines of the construction code for you, the ones where we added event listeners to the two buttons:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><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 /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">...</span> <span style="color: #009900; font-style: italic;">//create the visual elements</span><br />
<br />
&nbsp; &nbsp; addSentry<span style="color: #000000;">&#40;</span>submitButton<span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; isValid<span style="color: #000066; font-weight: bold;">,</span> sendInfoToServer<span style="color: #000066; font-weight: bold;">,</span> displayErrorMessages<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; addEnvoy<span style="color: #000000;">&#40;</span>resetButton<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>I can now simply remove both handler functions from my code and what remains is a class with a clean outline, less code and much easier to scan too. You may have noticed we don&#8217;t even mention the event type anymore. That&#8217;s because <a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank">Protection</a> has some default types mapped to some common classes, which of course you can override. Since on buttons we nearly always want to listen for MouseEvent.CLICK events, I don&#8217;t feel the necessity to always explicitly say so. And if you do want to register another type of event, there&#8217;s an optional parameter that can let you do just that.</p>
<p><strong>But, but, but, &#8230; sometimes I really need that event object in the handler, or at least some property of it&#8230;</strong><br />
Never fear, we can fix that in a jiffy. Suppose we wanted to validate the form as the user was typing. We might add the following to the construction:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><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 /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">addSentry<span style="color: #000000;">&#40;</span>mailInput<span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; isValid<span style="color: #000066; font-weight: bold;">,</span> enableSubmitButton<span style="color: #000066; font-weight: bold;">,</span> displayErrorMessages<span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=keyboardevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboardevent.html"><span style="color: #004993;">KeyboardEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_UP</span><br />
<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>mark<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;currentTarget.text&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>So what happens here? Instead of passing the entire Event object to the handlers, a certain property is extracted from the Event and passed only to the functions that require it. For instance:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;"><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 /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> isValid<span style="color: #000000;">&#40;</span>email<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> enableSubmitButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> displayErrorMessages<span style="color: #000000;">&#40;</span>email<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span></div></td></tr></tbody></table></div>
<p>Of course, you can do more complicated things to suit your needs, although <a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank">Protection</a>&#8216;s main goal will always be to make code clearer rather than obfuscate it. I will elaborate on the possibilities in ensuing posts since this one is already long enough.</p>
<p><strong>Hey, what about AS3Signals?</strong><br />
I know of <a title="AS3Signals" href="https://github.com/robertpenner/as3-signals" target="_blank">AS3Signals</a> of course. It&#8217;s a nice, mature library with quite some people working on it and many more using it. And it addresses very similar issues, or at least <a title="Robert Penner's critique of AS3 events" href="http://flashblog.robertpenner.com/2009/08/my-critique-of-as3-events-part-1.html" target="_blank">the same grievances with native AS event handling</a>.</p>
<p>But there is one reason why I&#8217;ve never really used it: it totally omits the native event system. I do understand the motivation behind this, but the reality is that I have to use components written by others which dispatch only native events and don&#8217;t have Signal properties. Not in the least the entire Flex component set.</p>
<p>So this, in <s>short</s> long, is why I created Protection. You can download it or check the source code on GitHub.</p>
<p><a title="Protection at GitHub" href="https://github.com/RIAstar/Protection" target="_blank"><img src="http://blog.riastar.net/wp-content/uploads/2011/08/github.png" alt="" title="github" width="32" height="32" class="alignnone size-full wp-image-63" />Protection on Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/development/protection-actionscript-guarding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RIAstar.children = [new Lena()];</title>
		<link>http://blog.riastar.net/design/riastar-children-new-lena/</link>
		<comments>http://blog.riastar.net/design/riastar-children-new-lena/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 18:48:41 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[birth card]]></category>
		<category><![CDATA[graphic design]]></category>
		<category><![CDATA[poetry]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=23</guid>
		<description><![CDATA[My five-week old daughter is lying next to me on the couch and is telling me that I ought to show the interwebs the beautiful birth card I made to announce her arrival in this world. Or at least, that&#8217;s (&#8230;)</p><p><a href="http://blog.riastar.net/design/riastar-children-new-lena/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">My five-week old daughter is lying next to me on the couch and is telling me that I ought to show the interwebs the beautiful birth card I made to announce her arrival in this world. Or at least, that&#8217;s what I gather from her babbling. So without further ado:</p>
<div id="attachment_24" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.riastar.net/wp-content/uploads/2011/04/presentation.jpg"><img class="size-medium wp-image-24" title="Presentation Lena's birth card" src="http://blog.riastar.net/wp-content/uploads/2011/04/presentation-300x225.jpg" alt="A presentation of Lena's birth card" width="300" height="225" /></a><p class="wp-caption-text">Click me, please!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/design/riastar-children-new-lena/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pixelate filter with Pixel Bender</title>
		<link>http://blog.riastar.net/labs/pixelate-filter-with-pixel-bender-4/</link>
		<comments>http://blog.riastar.net/labs/pixelate-filter-with-pixel-bender-4/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 01:26:07 +0000</pubDate>
		<dc:creator>RIAstar</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[pixel bender]]></category>

		<guid isPermaLink="false">http://blog.riastar.net/?p=13</guid>
		<description><![CDATA[Well, I finally found some time to dive into the Pixel Bender pool and start playing around with that new technology that came from Adobe-land. And this is what I came up with for my very first attempt: nothing too (&#8230;)</p><p><a href="http://blog.riastar.net/labs/pixelate-filter-with-pixel-bender-4/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Well, I finally found some time to dive into the Pixel Bender pool and start playing around with that new technology that came from Adobe-land. And this is what I came up with for my very first attempt: nothing too fancy, just the Pixel Bender version of the well known &#8221;Pixelate&#8221; PhotoShop filter. Give it a whirl by adjusting the pixel size with the slider. Flash Player 10 required of course.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="480" height="384">
      <param name="movie" value="http://labs.riastar.net/pixel_bender/PixelBender.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://labs.riastar.net/pixel_bender/PixelBender.swf" width="480" height="384">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>&nbsp;</p>
<p>You can check the source code at <a title="Pixelate experiment source" href="http://labs.riastar.net/pixel_bender/srcview/index.html" target="_blank">http://labs.riastar.net/pixel_bender/srcview/index.html</a> and here comes the Pixel Bender kernel source:</p>
<div class="codecolorer-container pixelbender twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:530px;height:400px;"><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 />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="pixelbender codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #0033ff;">languageVersion</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">1.0</span>;<span style="color: #000000; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #0033ff;">kernel</span> Pixelate<br />
<span style="color: #000000; font-weight: bold;">&lt;</span><br />
&nbsp; &nbsp;<span style="color: #666666;">namespace</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #990000;">&quot;net.riastar.shader&quot;</span>;<br />
&nbsp; &nbsp;<span style="color: #666666;">vendor</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #990000;">&quot;RIAstar&quot;</span>;<br />
&nbsp; &nbsp;<span style="color: #666666;">version</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">1</span>;<br />
&nbsp; &nbsp;<span style="color: #666666;">description</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #990000;">&quot;pixelates an image&quot;</span>;<br />
<span style="color: #000000; font-weight: bold;">&gt;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">input</span> <span style="color: #0033ff;">image4</span> src;<br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">output</span> <span style="color: #0033ff;">pixel4</span> dst;<br />
<br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">parameter</span> <span style="color: #0033ff;">float</span> size<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666;">minValue</span><span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">1.0</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666;">maxValue</span><span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">20.0</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666;">defaultValue</span><span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">4.0</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&gt;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #0033ff;">void</span> <span style="color: #0033ff; font-weight: bold;">evaluatePixel</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff;">float2</span> pos <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #333333;">outCoord</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff;">float</span> center <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #000000;">&#40;</span>size <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2.0</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; dst <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #333333;">sampleNearest</span><span style="color: #000000;">&#40;</span>src, <span style="color: #0033ff;">float2</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos.<span style="color: #000000;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #333333;">mod</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #000000;">x</span>, size<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> center,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos.<span style="color: #000000;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #333333;">mod</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #000000;">y</span>, size<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> center<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">//make sure not to sample outside the borders</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #9900cc; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dst.<span style="color: #000000;">a</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt;<span style="color: #000000; font-weight: bold;">=</span> <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dst <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #333333;">sampleNearest</span><span style="color: #000000;">&#40;</span>src, <span style="color: #0033ff;">float2</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #000000;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #333333;">mod</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #000000;">x</span>, size<span style="color: #000000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos.<span style="color: #000000;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #333333;">mod</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #000000;">y</span>, size<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>I had quite a hard time getting it to work in ActionScript, apparently because I installed the Flex 3.3 SDK just a week ago. Just putting a declaration of a flash.display.Shader class in my code, was sufficient to stop all code from executing, although the VM did not crash. I also got no error message whatsoever.</p>
<p>So after a whole hour of trying everything I could think of, I told the compiler to use the old 3.2 SDK and tadaa: working like a charm. Is it a bug in 3.3 (which was meant to be a bugfix release in the first place) or did I do something wrong?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.riastar.net/labs/pixelate-filter-with-pixel-bender-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

