<?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>MikeCann.co.uk &#187; Actionscript</title>
	<atom:link href="http://mikecann.co.uk/category/programming/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikecann.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 04 Sep 2010 23:28:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Joa Does It Again!</title>
		<link>http://mikecann.co.uk/programming/joa-does-it-again/</link>
		<comments>http://mikecann.co.uk/programming/joa-does-it-again/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 23:28:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[joa]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[player]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1298</guid>
		<description><![CDATA[So I have written about Mr Joa &#8216;The Flash God&#8217; Ebert before. He is well known throughout the Flash community for his incredible coding skills, particularly his work on low-level SWF optimisation. His latest project is called JITB and its nothing short of stunning as this video taken from his blog shows: Basically he has gone [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/08/ScreenHunter_01-Aug.-31-14.04.jpg"><img class="alignnone size-full wp-image-1300" title="ScreenHunter_01 Aug. 31 14.04" src="http://mikecann.co.uk/wp-content/uploads/2010/08/ScreenHunter_01-Aug.-31-14.04.jpg" alt="" width="678" height="380" /></a></p>
<p>So I have <a href="http://mikecann.co.uk/flash/funk-ioc-a-new-dependency-injection-framework/">written about Mr Joa &#8216;The Flash God&#8217; Ebert before</a>. He is well known throughout the Flash community for his incredible coding skills, particularly his work on low-level SWF optimisation.</p>
<p>His latest project is called JITB and its nothing short of stunning as this video taken <a href="http://blog.joa-ebert.com/2010/08/31/so-i-recorded-a-new-video/">from his blog</a> shows:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="700" height="550" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/atzHF7YGp6Y?fs=1&amp;hl=en_GB&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="700" height="550" src="http://www.youtube.com/v/atzHF7YGp6Y?fs=1&amp;hl=en_GB&amp;hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Basically he has gone and written a Flash Player in Java. What this means is that you get all those awesome speed benefits and optimisations that the Java team has worked hard for years and years to implement but you can write it all in a language already familiar and sexy, AS3! The result? You get about a 30x speedup! (disclaimer: a micro-benchmark taken from Joa&#8217;s blog)</p>
<p>This is all great news and very exciting. I cant wait to see a custom browser plugin using this flash player, or even having Pixel Bender shaders running on the hardware *me drools in anticipation*.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/programming/joa-does-it-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3, Dictionary &amp; Weak Method Closures</title>
		<link>http://mikecann.co.uk/personal-project/as3-dictionary-weak-method-closures/</link>
		<comments>http://mikecann.co.uk/personal-project/as3-dictionary-weak-method-closures/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 19:44:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SWFt]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[as3signals]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[RobotLegs]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1213</guid>
		<description><![CDATA[This is going to be a technical post so those of you not of the code persuasion look away now.. Okay great, now those guys have gone I can get down to it. Some of my recent work on the SWFt project has revolved around the use of Robert Penners AS3Signals. If you dont know what Signals [...]]]></description>
			<content:encoded><![CDATA[<p>This is going to be a technical post so those of you not of the code persuasion look away now..</p>
<p>Okay great, now those guys have gone I can get down to it.</p>
<p>Some of my recent work on the <a href="http://swft.co.uk/">SWFt project</a> has revolved around the use of <a href="http://robertpenner.com/flashblog/">Robert Penners AS3Signals</a>. If you dont know what Signals are I strongly reccomend that you check out Roberts blog for more info. In brief, they are an alternative to the Events system found in Flash, based on the Signal / Slot pattern of Qt and C# they are much faster and more elegant (my opinion) than native events.</p>
<p>I have been trying to incorporate signals in SWft for both the elegance and performance gains that they bring, however there is an issue that was brought to my attention by Shaun Smith on the mailing list. The issue is that my current use of them will cause memory leaks.</p>
<p>I realised that this too would apply to the work I had been doing using the RobotLegs and Signals libraries. RobotLegs (for those of you that dont know) is an excellent Dependency Injection framework inspired by the very popular PureMVC framework. I have <a href="http://mikecann.co.uk/personal-projects/on-the-bleeding-edge/">blogged</a> before <a href="http://mikecann.co.uk/programming/robotlegs-mvcs-relationship-diagram/">about</a> its <a href="http://mikecann.co.uk/personal-project/swft-dependency-injection-component-based-game-framework/">excellence</a>. Signals have been incorporated into RobotLegs as a separate &#8217;plugin&#8217; by <a href="http://joelhooks.com/2010/02/14/robotlegs-as3-signals-and-the-signalcommandmap-example/">Joel Hooks in the form of the SignalCommandMap</a>. The SignalCommandMap does as the name implies, it allows you to map signals to commands so that whenever a mapped signal is dispatched then the corresponding command is executed.</p>
<p>Its a very nice, elegant, solution to RIA development. However there is one catch. I have so far been using signals such as:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw1">public</span> <span class="kw4">class</span> MyMediator <span class="kw1">extends</span> Mediator</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="co1">// View</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#91;</span>Inject<span class="br0">&#93;</span> <span class="kw1">public</span> <span class="kw2">var</span> view <span class="sy0">:</span> MyView<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="co1">// Signals</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#91;</span>Inject<span class="br0">&#93;</span> <span class="kw1">public</span> <span class="kw2">var</span> eventOccured <span class="sy0">:</span> ViewEventOccuredSignal<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#91;</span>Inject<span class="br0">&#93;</span> <span class="kw1">public</span> <span class="kw2">var</span> modelChanged <span class="sy0">:</span> ModelChangedSignal<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	override <span class="kw1">public</span> <span class="kw3">function</span> onRegister<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		view<span class="sy0">.</span>someSignal<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span>eventOccured<span class="sy0">.</span>dispatch<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		modelChanged<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span>onModelChanged<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span>	</div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">protected</span> <span class="kw3">function</span> onModelChanged<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		view<span class="sy0">.</span>updateView<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>So here we can see a typical use of Signals in a mediator. There are two things going on here that are of concern, lets break them down.</p>
<p>Firstly on line 12 we are listening to a signal on the view, then passing on the event directly to an app-level event, notice how nice and clean this is, this is what I love about using RL &amp; Signals. Line 13 we are listening for an app-level signal for a change on the model then updating the view to reflect this.</p>
<p>It all looks well and good but unfortunately in its current state it could cause a memory leak. This is because we are listening to events on signals without then removing the listen. For example, we are listening to the app-level event on line 13 &#8220;modelChanged.add(onModelChanged);&#8221; so now the &#8220;modelChanged&#8221; signal has a reference to this Mediator. This will cause a leak when the View is removed from the display list. Normally the mediator would also be make available for garbage collection, however, because the singleton Signal has a reference to the Mediator it cannot be removed.</p>
<p>The same goes for line 12. Suppose the &#8220;ViewEventOccuredSignal&#8221; that is injected is not a singleton and is swapped out for another instance it could not be garbage collected as the &#8220;view.someSignal&#8221; has a reference to its dispatch function.</p>
<p>Realising this problem I knew that the solution was simply to be careful and add a &#8220;onRemoved&#8221; override function in my Mediator then clean up by removing the signal listeners. However I like the simplicity and beauty of current way of doing things so I started to wonder if there was another way.</p>
<p>I started thinking about whether I could use weak references with the Signal. If I could then I wouldnt have to worry about cleaning up as the Signal wouldnt store any hard-references to the functions and so the listener would be free for collection. After some digging however I realised that there was no option for weak listening in Robert Penners AS3Signals.</p>
<p>I thought to myself why the hell not? I knew that the Dictionary object in AS3 has an option to store its contents weakly so I thought so long as you don&#8217;t require order dependant execution of your listeners it should be possible to store the listener functions in a weakly referenced Dictionary.</p>
<p>It was at this point that I noticed Roberts post on the subject of weakly referenced Signals: <a href="http://flashblog.robertpenner.com/2009/09/as3-events-7-things-ive-learned-from.html">http://flashblog.robertpenner.com/2009/09/as3-events-7-things-ive-learned-from.html</a>. In it he references Grant Skinners post concerning a bug with storing functions in a weakly referenced Dictionary.</p>
<p>From Grant&#8217;s post:</p>
<blockquote><p>Note that there is a known bug with Dictionary that prevents it from operating correctly with references to methods. It seems that Dictionary does not resolve the method reference properly, and uses the closure object (ie. the &#8220;behind the scenes&#8221; object that facilitates method closure by maintaining a reference back to the method and its scope) instead of the function as the key. This causes two problems: the reference is immediately available for collection in a weak Dictionary (because while the method is still referenced, the closure object is not), and it can create duplicate entries if you add the same method twice. This can cause some big problems for things like doLater queues.</p></blockquote>
<p>This was starting to look bad for my idea. Me being me however, I thought I knew better, and that post was written pre Flash 10 so I thought to myself: perhaps its been fixed in Flash 10. So I set to work coding a simple example.</p>
<p>I created a very simple Signal dispatcher:</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">package</span></div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">import</span> <span class="kw6">flash.events</span><span class="sy0">.</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span class="kw5">EventDispatcher</span></a><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">import</span> <span class="kw6">flash.utils</span><span class="sy0">.</span><a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span class="kw5">Dictionary</span></a><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw4">class</span> SimpleDispatcher</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<span class="kw1">protected</span> <span class="kw2">var</span> _listeners <span class="sy0">:</span> <a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span class="kw5">Dictionary</span></a><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="kw1">public</span> <span class="kw3">function</span> SimpleDispatcher<span class="br0">&#40;</span>useWeak<span class="sy0">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span class="kw5">Boolean</span></a><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">			_listeners = <span class="kw1">new</span> <a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span class="kw5">Dictionary</span></a><span class="br0">&#40;</span>useWeak<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw7">add</span><span class="br0">&#40;</span>f<span class="sy0">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span class="kw5">Function</span></a><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">void</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">			_listeners<span class="br0">&#91;</span>f<span class="br0">&#93;</span> = <span class="kw1">true</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="kw1">public</span> <span class="kw3">function</span> dispatch<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">void</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">			<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> o<span class="sy0">:*</span> <span class="kw1">in</span> _listeners<span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">			<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">				o<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">			<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>And a very simple listening object:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">package</span></div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw4">class</span> SimpleListener</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<span class="kw1">public</span> <span class="kw3">function</span> listen<span class="br0">&#40;</span><span class="kw7">d</span><span class="sy0">:</span>SimpleDispatcher<span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">void</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">			<span class="kw7">d</span><span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span>onPing<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="kw1">protected</span> <span class="kw3">function</span> onPing<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">void</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">			<span class="kw7">trace</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">+</span><span class="st0">&quot; - ping&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>And then a simple Application to hook it all together:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="mxml" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc3">&lt;?xml version=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span>?<span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3"><span class="re1">&lt;s:Application</span> xmlns:fx=<span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">			   xmlns:s=<span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">			   xmlns:mx=<span class="st0">&quot;library://ns.adobe.com/flex/mx&quot;</span><span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="sc3"><span class="re1">&lt;fx:Script</span><span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1">		<span class="sc3">&lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">			import mx.controls.List;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3">			protected var _dispatcher : SimpleDispatcher = new SimpleDispatcher<span class="br0">&#40;</span>true<span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">			protected var _listener : SimpleListener;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3">			protected function onAddListenerClicked<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:void</span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#123;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">				_listener = new SimpleListener<span class="br0">&#40;</span><span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">				_listener.listen<span class="br0">&#40;</span>_dispatcher<span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#125;</span>	</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3">			protected function onRunGCClicked<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:void</span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#123;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">				try</span></div></li><li class="li1"><div class="de1"><span class="sc3">				<span class="br0">&#123;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">					new LocalConnection<span class="br0">&#40;</span><span class="br0">&#41;</span>.connect<span class="br0">&#40;</span><span class="st0">'foo'</span><span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">					new LocalConnection<span class="br0">&#40;</span><span class="br0">&#41;</span>.connect<span class="br0">&#40;</span><span class="st0">'foo'</span><span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">				<span class="br0">&#125;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">				catch <span class="br0">&#40;</span>e:*<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#125;</span>				</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3">			protected function onDispatchClicked<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:void</span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#123;</span></span></div></li><li class="li1"><div class="de1"><span class="sc3">				_dispatcher.dispatch<span class="br0">&#40;</span><span class="br0">&#41;</span>;</span></div></li><li class="li1"><div class="de1"><span class="sc3">			<span class="br0">&#125;</span>		</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3">		<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1">	<span class="sc3"><span class="re1">&lt;/fx:Script</span><span class="re2">&gt;</span></span>	</div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="sc3"><span class="re1">&lt;s:VGroup</span> width=<span class="st0">&quot;100%&quot;</span> height=<span class="st0">&quot;100%&quot;</span> horizontalAlign=<span class="st0">&quot;center&quot;</span> verticalAlign=<span class="st0">&quot;middle&quot;</span><span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1">		<span class="sc3"><span class="re1">&lt;s:Button</span> label=<span class="st0">&quot;Add Listener&quot;</span> click=<span class="st0">&quot;onAddListenerClicked(event)&quot;</span> <span class="re2">/&gt;</span></span></div></li><li class="li1"><div class="de1">		<span class="sc3"><span class="re1">&lt;s:Button</span> label=<span class="st0">&quot;Run GC&quot;</span> click=<span class="st0">&quot;onRunGCClicked(event)&quot;</span> <span class="re2">/&gt;</span></span></div></li><li class="li1"><div class="de1">		<span class="sc3"><span class="re1">&lt;s:Button</span> label=<span class="st0">&quot;Dispatch&quot;</span> click=<span class="st0">&quot;onDispatchClicked(event)&quot;</span> <span class="re2">/&gt;</span></span></div></li><li class="li1"><div class="de1">	<span class="sc3"><span class="re1">&lt;/s:VGroup</span><span class="re2">&gt;</span></span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="sc3"><span class="re1">&lt;/s:Application</span><span class="re2">&gt;</span></span></div></li></ol></pre></div></div>
<p>So what I should expect to see from this example is that when I click &#8220;Add Listener&#8221; it should create a listener reference which will then listen for when the signal is dispatched and trace out a &#8220;ping&#8221;.</p>
<p>What actually happens is you get nothing. No trace out, despite the fact that there is clearly still a reference to the listener in the Application file.</p>
<p>So whats happening here? If you break into the debugger at the point that the listener is added then you get the following:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/08/ScreenHunter_01-Aug.-16-14.03.jpg"><img class="alignnone size-full wp-image-1221" title="ScreenHunter_01 Aug. 16 14.03" src="http://mikecann.co.uk/wp-content/uploads/2010/08/ScreenHunter_01-Aug.-16-14.03.jpg" alt="" width="693" height="323" /></a></p>
<p>You can see that the type &#8220;MethodClosure&#8221; is added as the key to the dictionary rather than Function which is passed in. MethodClosure is a special native Flash Type that you dont have access to. It exists to resolve the issues we used to have in AS2 where passing a function of a class to a listener would cause the listener to go out of scope and other nasties. From the <a href="http://www.adobe.com/devnet/actionscript/articles/actionscript3_overview.html">Adobe docs</a>:</p>
<blockquote><p>Event handling is simplified in ActionScript 3.0 thanks to method closures, which provide built-in event delegation. In ActionScript 2.0, a closure would not remember what object instance it was extracted from, leading to unexpected behavior when the closure was invoked.</p></blockquote>
<p>..</p>
<blockquote><p>This class is no longer needed because in ActionScript 3.0, a method closure will be generated when someMethod is referenced. The method closure will automatically remember its original object instance.</p></blockquote>
<p>The only problem is that it seems that using a MethodClosure as a key in a weak dictionary causes the MethodClosure to have no references and hence be free for garbage collection as soon as its added to the Dictionary which is not good <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>So thats about as far as I got, I have spent a few evenings on this one now and I think im about ready to call it quits. I had a few ideas about creating Delegate handlers to make functions very much in the same way as was done in AS2 but then I read this post: <a href="http://blog.betabong.com/2008/09/26/weak-method-closure/">http://blog.betabong.com/2008/09/26/weak-method-closure/</a> and the subsequent comments and realised it probably wasnt going to work.</p>
<p>I also had an idea about using the only other method of holding weak references the EventDispatcher class. I thought perhaps somehow I could get it to hold the weak references then I could loop through the listeners in there calling dispatch manually. Despite &#8220;listeners&#8221; property showing up in the Flex debugger for an EventDispatcher you dont actually have access to that property unfortunately so hence cant get access to the listening functions. Interestingly however the EventDispatcher uses &#8220;WeakMethodClosure&#8221; object instead of the &#8220;MethodClosure&#8221; object according to the debugger.</p>
<p>Well I guess for now Ill have to make sure I code more carefully and unlisten from my Signals <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/as3-dictionary-weak-method-closures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex 4 Spark &amp; Rollover Group Containing Rect</title>
		<link>http://mikecann.co.uk/programming/flex-4-spark-rollover-group-containing-rect/</link>
		<comments>http://mikecann.co.uk/programming/flex-4-spark-rollover-group-containing-rect/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 08:25:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Behaviour]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Expected]]></category>
		<category><![CDATA[Flex4]]></category>
		<category><![CDATA[Group]]></category>
		<category><![CDATA[Rollover]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1159</guid>
		<description><![CDATA[Was working on my top-secret Flex-based project over the weekend when I discovered something I hadn&#8217;t come across before. The issue is that when you have a Spark Rect GraphicsElement within a Spark Group it seems that the rollover event of the group is triggered even though the mouse doesn&#8217;t roll over the Rect. Here is a video I made to [...]]]></description>
			<content:encoded><![CDATA[<p>Was working on my top-secret Flex-based project over the weekend when I discovered something I hadn&#8217;t come across before.</p>
<p>The issue is that when you have a Spark Rect GraphicsElement within a Spark Group it seems that the rollover event of the group is triggered even though the mouse doesn&#8217;t roll over the Rect.</p>
<p>Here is a video I made to explain my issue on Twitter:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="700" height="550" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/9Ku4xY7vfyw&amp;hl=en_GB&amp;fs=1?hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="700" height="550" src="http://www.youtube.com/v/9Ku4xY7vfyw&amp;hl=en_GB&amp;fs=1?hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The code in the video is as follows:</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="mxml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;s:WindowedApplication</span> xmlns:fx=<span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span class="sc3">   xmlns:s=<span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span class="sc3">   xmlns:mx=<span class="st0">&quot;library://ns.adobe.com/flex/mx&quot;</span><span class="re2">&gt;</span></span> 
&nbsp;
	<span class="sc3"><span class="re1">&lt;s:Group</span> rollOver=<span class="st0">&quot;trace('ya')&quot;</span><span class="re2">&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;s:Rect</span> x=<span class="st0">&quot;100&quot;</span> y=<span class="st0">&quot;100&quot;</span> width=<span class="st0">&quot;20&quot;</span> height=<span class="st0">&quot;20&quot;</span><span class="re2">&gt;</span></span>
			<span class="sc3"><span class="re1">&lt;s:fill</span><span class="re2">&gt;</span></span>
				<span class="sc3"><span class="re1">&lt;s:SolidColor</span> color=<span class="st0">&quot;0x00ff00&quot;</span> <span class="re2">/&gt;</span></span>
			<span class="sc3"><span class="re1">&lt;/s:fill</span><span class="re2">&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;/s:Rect</span><span class="re2">&gt;</span></span>
	<span class="sc3"><span class="re1">&lt;/s:Group</span><span class="re2">&gt;</span></span> 
&nbsp;
<span class="sc3"><span class="re1">&lt;/s:WindowedApplication</span><span class="re2">&gt;</span></span></pre></div></div>
<p>It turns out (after <a href="http://forums.adobe.com/message/3017631#3017631">posting the issue on the Adobe Forums</a>) that I was simply missing the &#8220;mouseEnabledWhereTransparent&#8221; property on the Group. Setting it to false causes the mouse to perform a hit-test rather than a simple bounds check. Thank you Mr Shongrunden for pointing this out to me <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So this now works:</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="sy0">&lt;</span>s<span class="sy0">:</span>WindowedApplication xmlns<span class="sy0">:</span>fx<span class="sy0">=</span><span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
   xmlns<span class="sy0">:</span>s<span class="sy0">=</span><span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span>
   xmlns<span class="sy0">:</span>mx<span class="sy0">=</span><span class="st0">&quot;library://ns.adobe.com/flex/mx&quot;</span><span class="sy0">&gt;</span> 
&nbsp;
	<span class="sy0">&lt;</span>s<span class="sy0">:</span>Group rollOver<span class="sy0">=</span><span class="st0">&quot;trace('ya')&quot;</span> mouseEnabledWhereTransparent<span class="sy0">=</span><span class="st0">&quot;false&quot;</span><span class="sy0">&gt;</span>
		<span class="sy0">&lt;</span>s<span class="sy0">:</span>Rect x<span class="sy0">=</span><span class="st0">&quot;100&quot;</span> y<span class="sy0">=</span><span class="st0">&quot;100&quot;</span> width<span class="sy0">=</span><span class="st0">&quot;20&quot;</span> height<span class="sy0">=</span><span class="st0">&quot;20&quot;</span><span class="sy0">&gt;</span>
			<span class="sy0">&lt;</span>s<span class="sy0">:</span>fill<span class="sy0">&gt;</span>
				<span class="sy0">&lt;</span>s<span class="sy0">:</span>SolidColor color<span class="sy0">=</span><span class="st0">&quot;0x00ff00&quot;</span> <span class="sy0">/&gt;</span>
			<span class="sy0">&lt;/</span>s<span class="sy0">:</span>fill<span class="sy0">&gt;</span>
		<span class="sy0">&lt;/</span>s<span class="sy0">:</span>Rect<span class="sy0">&gt;</span>
	<span class="sy0">&lt;/</span>s<span class="sy0">:</span>Group<span class="sy0">&gt;</span> 
&nbsp;
<span class="sy0">&lt;/</span>s<span class="sy0">:</span>WindowedApplication<span class="sy0">&gt;</span></pre></div></div>
<p>I hope this helps someone else out!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/programming/flex-4-spark-rollover-group-containing-rect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funk IoC &#8211; A New Dependency Injection Framework</title>
		<link>http://mikecann.co.uk/flash/funk-ioc-a-new-dependency-injection-framework/</link>
		<comments>http://mikecann.co.uk/flash/funk-ioc-a-new-dependency-injection-framework/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 20:17:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Functional]]></category>
		<category><![CDATA[Funk]]></category>
		<category><![CDATA[Impressive]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Robot Legs]]></category>
		<category><![CDATA[Swift Suspenders]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=1020</guid>
		<description><![CDATA[Twitter can be a funny beast, what makes it great can also make it poor. I use Twhirl which keeps me updated any time one of the people I follow tweets about something, the only problem is that so many people tweet that if I dont happen to see it within about and hour or so of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/04/ScreenHunter_01-Apr.-08-20.11.gif"><img class="alignnone size-full wp-image-1023" title="ScreenHunter_01 Apr. 08 20.11" src="http://mikecann.co.uk/wp-content/uploads/2010/04/ScreenHunter_01-Apr.-08-20.11.gif" alt="" width="710" height="164" /></a></p>
<p>Twitter can be a funny beast, what makes it great can also make it poor. I use <a href="http://www.twhirl.org/">Twhirl </a>which keeps me updated any time one of the people I follow tweets about something, the only problem is that so many people tweet that if I dont happen to see it within about and hour or so of the Tweet, ill miss it. This time however I was lucky enough to catch a tweet by <a href="http://twitter.com/joa">@Joa</a> about his new Inversion of Control and functional-programming-like library, <a href="http://code.google.com/p/funk-as3/">Funk AS3</a>.</p>
<p>As I have been getting well into <a href="http://www.robotlegs.org/">RobotLegs</a> (a Dependency Injection MVCS framework) recently I was extremely interested to hear about this new project by Joa who I respect very much as a brilliant coder not least because of his excellent work on low-level Flash byte-code optimisation (see <a href="http://code.google.com/p/apparat/">Apparat</a>).</p>
<p>Joa has taken a different approach to doing dependency injection. The approach most frequently used (and the one used in SwiftSuspenders / RobotLegs) is to use meta-data to declare to a number of variables for injection. You then map a class to be injected and instantiate it using the injector.</p>
<p>As an example, with Swift Suspenders you would define a class for injection with something like the following:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">class</span> MyInjectedClass</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> sayHello<span class="br0">&#40;</span>toSay<span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<span class="kw7">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Hello &quot;</span><span class="sy0">+</span>toStay<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">var</span> injector <span class="sy0">:</span> Injector = <span class="kw1">new</span> Injector<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">injector<span class="sy0">.</span>mapSingleton<span class="br0">&#40;</span>MyInjectedClass<span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>Here we are telling the Injector to make a single instance of our class and hold it internally ready for when it is next requested, such as:</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">class</span> MyDependantClass</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#91;</span>Inject<span class="br0">&#93;</span> <span class="kw1">public</span> <span class="kw2">var</span> myClass <span class="sy0">:</span> MyInjectedClass<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> performAction<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		myClass<span class="sy0">.</span>sayHello<span class="br0">&#40;</span><span class="st0">&quot;World&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>Here the [Inject] meta-data indicates that we want the framework to supply the class with an instance of type MyInjectedClass. The final part is to make an instance of the dendant class and inject into it:</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">var</span> dependant <span class="sy0">:</span> MyDependantClass = <span class="kw1">new</span> MyDependantClass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">injector<span class="sy0">.</span>injectInto<span class="br0">&#40;</span>dependant<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">dependant<span class="sy0">.</span>performAction<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>As you can see this is a nice way of handling inter-module dependencies in your code, when coupled with a MVC framework such as RobotLegs it becomes and extremely powerful yet elegant way of coding.</p>
<p>It however isnt perfect and Joa, on his <a href="http://code.google.com/p/funk-as3/wiki/IoC">google code page</a> mentions three drawbacks of this method:</p>
<ul>
<blockquote>
<li>Your injected properties are publicly exposed and mutable.</li>
<li>describeType is very expensive.</li>
<li>Steep learning curve.</li>
</blockquote>
</ul>
<p>This is where he suggests his alternative method, which is quite ingenious. Using the same example as above you would see something like the following:</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">class</span> MyInjectedClass</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> sayHello<span class="br0">&#40;</span>toSay<span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<span class="kw7">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Hello &quot;</span><span class="sy0">+</span>toStay<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">bind<span class="br0">&#40;</span>MyInjectedClass<span class="br0">&#41;</span><span class="sy0">.</span>asSingleton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>Then the dependant class would look like the following:</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">class</span> MyInjectedClass</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">protected</span> <span class="kw2">var</span> myClass <span class="sy0">:</span> MyInjectedClass = inject<span class="br0">&#40;</span>MyInjectedClass<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> performAction<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		myClass<span class="sy0">.</span>sayHello<span class="br0">&#40;</span><span class="st0">&quot;World&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>And making an instance of it could be as simple as:</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">var</span> dependant <span class="sy0">:</span> MyDependantClass = <span class="kw1">new</span> MyDependantClass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">dependant<span class="sy0">.</span>performAction<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>As can be seen there are some benefits to this method, the biggest one in my opinion is that injected properties dont have to be public as they are provided by the call from within the class scope rather than from outside.</p>
<p>So how does Joa perform this magic? By abusing a little used ability of the Actionscript programming language known as package-level-functions. These are throwbacks from the old AS1 &amp; AS2 days of global functions. There are actually a couple of common examples in AS3 still such as getTimer() and getQualifiedClassName() still used. What Joa has done is to use these package level functions as a method of generating concise looking code reminiscent of functional programming.</p>
<p>Performance wise, im not entirely sure whether by using package-level functions instead of describeType() calls used in meta-data driven IoC frameworks is any faster as Till Schneidereit of Swift Suspenders suggests:</p>
<blockquote><p>I don&#8217;t think that Funk&#8217;s approach is any faster than an optimized<br />
metadata-based IoC container: describeType may be slow (as in &#8220;takes a<br />
few dozen microseconds to run&#8221;), but is only ever called once for each<br />
class an instance of which is injected into. After that, it&#8217;s just a<br />
straight iteration over an array for all injection points instead of<br />
Funk&#8217;s multiple method calls for each injection point.</p></blockquote>
<p>So the next step for me is to run some tests to see how things pan out. Either way im very impressed with both approaches and cant wait to see what kind of exciting advances will be developed in the coming months.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/flash/funk-ioc-a-new-dependency-injection-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scribble v0.1 &#8230; Harmony, but in Flash.. kinda!</title>
		<link>http://mikecann.co.uk/art/scribble-v0-1-harmony-but-in-flash-kinda/</link>
		<comments>http://mikecann.co.uk/art/scribble-v0-1-harmony-but-in-flash-kinda/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:00:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Art]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Harmony]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=973</guid>
		<description><![CDATA[Well as you can probably tell from my last few posts, I have been loving the simple browser drawing app called Harmony. Well, while playing with it I thought to myself, &#8220;Is there a reason this cant be done in Flash?&#8221;. Well this is the answer to my question. I have called it Scribble and [...]]]></description>
			<content:encoded><![CDATA[<p>Well as you can probably tell from my <a href="http://www.mikecann.co.uk/art/harmony-html5-procedural-drawing/">last</a> few <a href="http://www.mikecann.co.uk/art/more-harmony-creations/">posts</a>, I have been loving the simple browser drawing app called <a href="http://mrdoob.com/projects/harmony/">Harmony</a>. Well, while playing with it I thought to myself, &#8220;Is there a reason this cant be done in Flash?&#8221;. Well this is the answer to my question.</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/03/ScreenHunter_03-Mar.-25-18.47.gif"><img class="alignnone size-full wp-image-974" title="ScreenHunter_03 Mar. 25 18.47" src="http://mikecann.co.uk/wp-content/uploads/2010/03/ScreenHunter_03-Mar.-25-18.47.gif" alt="" width="700" height="392" /></a></p>
<p>I have called it Scribble and its very basic at the moment, not containing even many of the simple features in Harmony, I do however intend to keep adding to it. So over the course of several weeks I hope to add bit by bit till it becomes a fun little place to Scribble!</p>
<p>Anyways, you can check out the current state of the thing here &#8211;&gt; <a href="http://www.mikecann.co.uk/flash/Scribble_v0-1/Scribble.html">http://www.mikecann.co.uk/flash/Scribble_v0-1/Scribble.html</a></p>
<p>Splendid!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/art/scribble-v0-1-harmony-but-in-flash-kinda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RobotLegs MVCS Relationship Diagram</title>
		<link>http://mikecann.co.uk/programming/robotlegs-mvcs-relationship-diagram/</link>
		<comments>http://mikecann.co.uk/programming/robotlegs-mvcs-relationship-diagram/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 18:17:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Robot Legs]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=954</guid>
		<description><![CDATA[Just as a follow up from my post on the bleeding edge I thought I would post a rather interesting image @srivello made and @jhooks shared. Its a relationship between the main components in the MVCS meta-framework in RobotLegs. Its pretty good for anyone that (like me) preferrs to see a diagram when trying to [...]]]></description>
			<content:encoded><![CDATA[<p>Just as a follow up from my post <a href="http://www.mikecann.co.uk/programming/on-the-bleeding-edge/">on the bleeding edge</a> I thought I would post a rather interesting image @srivello made and @jhooks shared. Its a relationship between the main components in the MVCS meta-framework in <a href="http://www.robotlegs.org">RobotLegs</a>. Its pretty good for anyone that (like me) preferrs to see a diagram when trying to grasp the concept of a new framework:</p>
<p>(click to enlarge)</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/03/ScreenHunter_01-Mar.-23-15.51.jpg"><img class="alignnone size-full wp-image-955" title="ScreenHunter_01 Mar. 23 15.51" src="http://mikecann.co.uk/wp-content/uploads/2010/03/ScreenHunter_01-Mar.-23-15.51.jpg" alt="" width="655" height="445" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/programming/robotlegs-mvcs-relationship-diagram/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trance Around The World, Show Downloader</title>
		<link>http://mikecann.co.uk/personal-projects/trance-around-the-world-show-downloader/</link>
		<comments>http://mikecann.co.uk/personal-projects/trance-around-the-world-show-downloader/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 23:34:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[MP3]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Trance]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=938</guid>
		<description><![CDATA[Had this little idea a while back, thought I would spend an hour tonight and bash it out. I love the Trance Around The World radio show by Above and Beyond, downloading  it for listening later is very annoying however and involves some fiddling with browser source and other things, so to make life easier I built this little [...]]]></description>
			<content:encoded><![CDATA[<p>Had this little idea a while back, thought I would spend an hour tonight and bash it out.</p>
<p>I love the <a href="http://www.trancearoundtheworld.com/">Trance Around The World radio show by Above and Beyond</a>, downloading  it for listening later is very annoying however and involves some fiddling with browser source and other things, so to make life easier I built this little tool. What it does is grab the HTML from the above and beyond page then parse it for the MP3 file, then it uses the FileReference class in flash to download it to your HD.</p>
<p>Anyways, enough jibber jabber. Source is enabled:</p>
<p><div id="flashcontent1331" style="width:215px; height:180px;"><strong>Please upgrade your Flash Player</strong> This is the content that would be shown if the user does not have Flash Player 9.0.115 or higher installed.</div><script type="text/javascript">
<!-- // <![CDATA[
var so = new SWFObject("http://mikecann.co.uk/wp-content/plugins/air-badge/AIRInstallBadge.swf", "Badge", "215", "180", "9.0.115", "#FFFFFF");
so.useExpressInstall("http://mikecann.co.uk/wp-content/plugins/air-badge/expressinstall.swf");
so.addVariable("airversion", "1.0");
so.addVariable("appname", "TATW+Downloader");
so.addVariable("appurl", "http://www.mikecann.co.uk/wp-content/uploads/2010/03/TATWDownloaderAir.air");
so.addVariable("appid", "TATW+Downloader");
so.addVariable("pubid", "");
so.addVariable("appversion", "1");
so.addVariable("imageurl", "http://mikecann.co.uk/wp-content/uploads/2010/03/ScreenHunter_01-Mar.-04-23.45.gif");
so.addVariable("appinstallarg", "installed from web");
so.addVariable("applauncharg", "launched from web");
so.addVariable("helpurl", "help.html");
so.addVariable("hidehelp", "true");
so.addVariable("skiptransition", "false");
so.addVariable("titlecolor", "#00AAFF");
so.addVariable("buttonlabelcolor", "#00AAFF");
so.addVariable("appnamecolor", "#00AAFF");
so.addVariable("str_err_airswf", "<u>Running locally?</u><br/><br/>The AIR proxy swf won't load properly when this is run from the local file system.");
so.write("flashcontent1331");
// ]]&gt; -->
</script>
</p>
<p>Hope you enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-projects/trance-around-the-world-show-downloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the Bleeding Edge</title>
		<link>http://mikecann.co.uk/personal-projects/on-the-bleeding-edge/</link>
		<comments>http://mikecann.co.uk/personal-projects/on-the-bleeding-edge/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 22:26:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Inputtie]]></category>
		<category><![CDATA[Java FX]]></category>
		<category><![CDATA[Mate]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Robot Legs]]></category>
		<category><![CDATA[Signals]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=895</guid>
		<description><![CDATA[Well it thought it was about time I did some posting about my personal project im working on at the moment as I havent spoken about my coding for a while. For a while now (alot longer than I had hoped for) I have been working on a project that falls outside the realms of [...]]]></description>
			<content:encoded><![CDATA[<p>Well it thought it was about time I did some posting about my personal project im working on at the moment as I havent spoken about my coding for a while.</p>
<p>For a while now (alot longer than I had hoped for) I have been working on a project that falls outside the realms of my usual kind of games-related projects. Im not ready do describe exactly what it is yet but im excited about it.</p>
<p>For months I have been struggling with the techinal challenges the project has entailed and I have dabbled with many new and highly diverse technologies including <a href="http://www.mikecann.co.uk/programming/flirting-with-javafx/">JavaFX</a> (Java), Qt (C++) and Mono (C#).  I have been looking for a cross-platform technology that will get the job done that I need and doing it in an elegant manner.</p>
<p>I thought I had found it with a combination of JavaFX and straight Java using the PureMVC framework. I however was plagued with problems throughout with Bonjour, jGroups, JmDNS, JNI and JNA.</p>
<p>So after months of work, hardship and struggles I read a very interesting article on the up-and-coming Adobe AIR 2.0  that was opened for beta in December. With 2.0 Adobe are bringing NativeProcess  to Air. What this means is that you can you can execute native code (.dlls, .so, .jar etc) from Air. To me this was bloody brilliant as I had been<a href="http://www.mikecann.co.uk/programming/audiobook-organiser-v1-3-0-dragndrop/"> playing with Air reccently</a> and my <a href="http://www.mikecann.co.uk/photos-personal/playdemic-my-fist-day/">day-job</a> heavily involves Flex and I simply love the power and beauty of Flex.</p>
<p>So what this meant to me was that I could write the bulk of my project including its interface in my much preferred Adobe Flex (Air) and then use Native Process to communicate with a small kernel of Java that would do all the dirty work that Air itself cant do.</p>
<p>So after a little playing with <a href="http://www.riaspace.net/2010/01/flerry-flex-java-bridge-for-adobe-air-2-0/">Flerry</a> for Air-&gt;Java bridge I started to think about the structure of the code and the framework I would use. For my initial few runs at this project I had been using the Java version of PureMVC. I really like some aspects of PureMVC but I think its can be so overly cumbersome in some circumstances (ill write another post on this in the future I think). So instead I looked at the alternatives.</p>
<p>I have been using <a href="http://mate.asfusion.com/">Mate</a> alot recently at work and on my own mini-project the <a href="http://www.mikecann.co.uk/programming/audio-book-organiser-air-mate-flex-4/">Audio Book Organiser</a>. However as this project is partly for my own learning and personal growth I decided to look at what else there was out there. From the videos by <a href="http://www.mikecann.co.uk/fun-videos/jessie-warden-flash-flex-videos/">Jessie Warden</a> I had heard about <a href="http://www.robotlegs.org">Robot Legs</a>. Apparently this framework has been around for a while, but it was the first I had heard of it. Taking at look at it I immediately became very excited as it looks like it offers all the things that make PureMVC great but without the extra coding-baggage that goes with it.</p>
<p>To add to my interest it appears another very interesting, very new action-script technology has been introduced into Robot Legs called <a href="http://github.com/robertpenner/as3-signals">Signals </a>by Robert Penner. Signals is an alternative to the standard events dispatching method found throughout flash (more on this in another post).</p>
<p>So why have I called this post &#8220;the bleeding edge?&#8221;. Well Adobe Air 2.0 is still in beta and has only been for a month or so. Its so new that some parts still havent been documented atall and the only way to find out how they work is to post a msg to the devs on the forums. Signals is also new and its integration into Robot Legs is very new indeed (last coupple of weeks). So at the moment I feel as if im at the forefront of some very new, very exciting technology, a stark contrast to my fiddlings with the ancient Java.</p>
<p>I realise this post is very text and tech-heavy but I needed to post about it before I forgot all the pain I have gone through with this project to get where I am at the moment. Future posts ill be delving a little deeper into some of my experiments with these new technologies <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-projects/on-the-bleeding-edge/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AudioBook Organiser v1.3.0 &#8211; Drag&#039;n&#039;Drop</title>
		<link>http://mikecann.co.uk/personal-projects/audiobook-organiser-v1-3-0-dragndrop/</link>
		<comments>http://mikecann.co.uk/personal-projects/audiobook-organiser-v1-3-0-dragndrop/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 23:07:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Audiobook]]></category>
		<category><![CDATA[Drag-Drop]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=856</guid>
		<description><![CDATA[Well I was just doing some audio book organising and realised that it would be great if I could drag and drop a folder straight from my AIR into iTunes ready for upload to my iPhone. Anyways after a little searching through the docs I came up with this little ditty: var cp : Clipboard [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/01/ScreenHunter_04-Jan.-11-22.36.jpg"><img class="alignnone size-full wp-image-857" title="ScreenHunter_04-Jan.-11-22.36" src="http://mikecann.co.uk/wp-content/uploads/2010/01/ScreenHunter_04-Jan.-11-22.36.jpg" alt="" width="700" height="343" /></a></p>
<p>Well I was just doing some audio book organising and realised that it would be great if I could drag and drop a folder straight from my AIR into iTunes ready for upload to my iPhone.</p>
<p>Anyways after a little searching through the docs I came up with this little ditty:</p>
<pre>var cp : Clipboard = new Clipboard();
cp.setData(ClipboardFormats.FILE_LIST_FORMAT, [new File(book.url)], false);
NativeDragManager.doDrag(null,cp);</pre>
<div>Which gets fired by my DataGrid in the view:</div>
<pre>
<div>&lt;mx:DataGrid width="100%" height="100%" dataProvider="{books}" editable="true"</div>
<div>  itemEditEnd="{dispatchEvent(new BooksEvent(BooksEvent.PROPERTY_CHANGED));}"</div>
<div>  dragEnabled="true"</div>
<div>  dragStart="{dispatchEvent(new BooksEvent(BooksEvent.BOOK_BEGIN_DRAG, AudioBookModel(event.currentTarget.selectedItem)))}"&gt;</div>
</pre>
<div>Its pretty cool.</div>
<div>Anyways, the latest version and the source is below:</div>
<div>
<p><div id="flashcontent1894" style="width:215px; height:180px;"><strong>Please upgrade your Flash Player</strong> This is the content that would be shown if the user does not have Flash Player 9.0.115 or higher installed.</div><script type="text/javascript">
<!-- // <![CDATA[
var so = new SWFObject("http://mikecann.co.uk/wp-content/plugins/air-badge/AIRInstallBadge.swf", "Badge", "215", "180", "9.0.115", "#FFFFFF");
so.useExpressInstall("http://mikecann.co.uk/wp-content/plugins/air-badge/expressinstall.swf");
so.addVariable("airversion", "1.0");
so.addVariable("appname", "Audio+Book+Orgainser");
so.addVariable("appurl", "http://www.mikecann.co.uk/flash/AudioBookOrganiser/AudioBookOrganiser.air");
so.addVariable("appid", "Audio+Book+Orgainser");
so.addVariable("pubid", "");
so.addVariable("appversion", "1");
so.addVariable("imageurl", "http://www.mikecann.co.uk/flash/AudioBookOrganiser/badgeImg.jpg");
so.addVariable("appinstallarg", "installed from web");
so.addVariable("applauncharg", "launched from web");
so.addVariable("helpurl", "help.html");
so.addVariable("hidehelp", "true");
so.addVariable("skiptransition", "false");
so.addVariable("titlecolor", "#00AAFF");
so.addVariable("buttonlabelcolor", "#00AAFF");
so.addVariable("appnamecolor", "#00AAFF");
so.addVariable("str_err_airswf", "<u>Running locally?</u><br/><br/>The AIR proxy swf won't load properly when this is run from the local file system.");
so.write("flashcontent1894");
// ]]&gt; -->
</script>
<br />
Source: <a href="http://www.mikecann.co.uk/flash/AudioBookOrganiser/AudioBookOrganiser_v130_source.zip">http://www.mikecann.co.uk/flash/AudioBookOrganiser/AudioBookOrganiser_v130_source.zip</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-projects/audiobook-organiser-v1-3-0-dragndrop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quasimondo&#039;s Galactose</title>
		<link>http://mikecann.co.uk/programming/actionscript/quasimondos-galactose/</link>
		<comments>http://mikecann.co.uk/programming/actionscript/quasimondos-galactose/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 20:17:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Experiment]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.mikecann.co.uk/?p=830</guid>
		<description><![CDATA[I have immense respect for some of the flash developers out there and Quasimondo is one of them. He has just released a little particle related experiment. Whenever I see these kind of things it inspires me to bash out my own little experiments. I wont talk too much about it but check it out [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2010/01/ScreenHunter_02-Jan.-10-20.13.jpg"><img class="alignnone size-full wp-image-831" title="ScreenHunter_02 Jan. 10 20.13" src="http://mikecann.co.uk/wp-content/uploads/2010/01/ScreenHunter_02-Jan.-10-20.13.jpg" alt="ScreenHunter_02 Jan. 10 20.13" width="688" height="365" /></a></p>
<p>I have immense respect for some of the flash developers out there and Quasimondo is one of them. He has just released a little particle related experiment.</p>
<p>Whenever I see these kind of things it inspires me to bash out my own little experiments.</p>
<p>I wont talk too much about it but check it out on this lab page: <a href="http://incubator.quasimondo.com/flash/galactose.php">http://incubator.quasimondo.com/flash/galactose.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/programming/actionscript/quasimondos-galactose/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
