<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Building Blocks &#187; libraries</title>
	<atom:link href="http://joelhooks.com/category/libraries/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelhooks.com</link>
	<description>It's a magical world. Let's go exploring.</description>
	<lastBuildDate>Tue, 29 Jun 2010 18:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
		<item>
		<title>Modular Robotlegs</title>
		<link>http://joelhooks.com/2010/05/02/modular-robotlegs/</link>
		<comments>http://joelhooks.com/2010/05/02/modular-robotlegs/#comments</comments>
		<pubDate>Mon, 03 May 2010 04:08:50 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[robotlegs]]></category>
		<category><![CDATA[software architecture]]></category>

		<guid isPermaLink="false">http://joelhooks.com/?p=477</guid>
		<description><![CDATA[WTF is a Modular? Modular programming is a versatile technique for separating an application into smaller parts. Each module is effectively an application and can be developed independently from one another. In a typical modular application you will have a Shell that is loaded initially. The Shell will manage the loading of modules and displaying [...]]]></description>
			<content:encoded><![CDATA[<h2>WTF is a Modular?</h2>
<p>Modular programming is a versatile technique for separating an application into smaller parts. Each module is effectively an application and can be developed independently from one another. In a typical modular application you will have a Shell that is loaded initially. The Shell will manage the loading of modules and displaying their contents. Flex modules can be visual components that extend the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/modules/Module.html">Module</a> class, but this is certainly not the extent of what can be considered a module.<br />
<img src="http://69.164.207.135/wp-content/uploads/2010/05/ModularUtility4.png" alt="" title="ModularUtility" width="472" height="249" class="aligncenter size-full wp-image-502" /><br />
Robotlegs is well suited for modular application development. Each Context is encapsulated and provides its own internal method for communication. A barrier to writing modular applications thus far with Robotlegs is that while these Context objects can exist in abundance in an application, they aren't very useful from a modular standpoint unless they can communicate with one another. As with many things within the Robotlegs eco-system, this is best accomplished through the development of a utility that can be used in conjunction with the core framework to provide the specific functionality that we are looking for. There has been some good work done in this area, but with Robotlegs 1.1 and more specifically the 1.5 release of the default Dependency Injection provider SwiftSuspenders, we have been equipped with better tools to accomplish modular contexts in a Robotlegs application in a clean effective manner.<br />
<span id="more-503"></span></p>
<h2>A Little Backstory</h2>
<p>Prior to Robotlegs I used <a href="http://puremvc.org">PureMVC</a> exclusively. There is a utility for PureMVC called <a href="http://trac.puremvc.org/Utility_AS3_MultiCore_Pipes">Pipes</a>, which I have <a href="http://joelhooks.com/2009/05/18/piping-the-machine-puremvc-multicore-with-pipes-and-the-finite-state-machine-fsm/">written about previously</a>. Pipes is pretty cool. It uses a plumbing metaphor to describe the connections between modules. It is... verbose... and requires a shit-ton of wiring code to be functional. This can be a challenge to get your head around, and can create code that you have to stare at for a good while to fully understand HTF everything is actually being wired.</p>
<p>My original path for a Robotlegs modular utility was to port Pipes. In fact, I didn't really have to port Pipes, but just wrote an adapter that allowed Pipes to fit into a Robotlegs application. The problem was that it didn't feel like Robotlegs. Verbose and confusing goes against the core moral fiber of what Robotlegs is all about. So I started whittling it down. At that point it looked like <a href="http://github.com/Stray/robotlegs-utilities-Modular">Stray's excellent work with the Robotlegs Modular utility</a>. Heh. Full Circle! So instead of using Pipes, I've taken her work and expanded on it for Robotlegs 1.1 and at the same time clarifying some of the concepts within the utility and making it more useful across a broader range of use cases.</p>
<h2>Where we are now</h2>
<p>So with Pipes set aside for now, we have a dead simple modular implementation that can be used for Flex, AS3, and maybe even Flash applications. It doesn't provide all of the functionality that Pipes brings to the table. Specifically it is missing concepts like message filtering and queuing. While these are likely useful tools, I didn't feel that they needed to be implemented just yet. I have some ideas about how they might be implemented, but feel that the Robotlegs Modular Utility is clean and simple covering a big majority of typical use cases. Start simple and expand from there. This is where I am relying on you, gentle reader, to help guide the utility into something more useful while still keeping the clean and simple Robotlegs aesthetic.</p>
<p>With that behind us, lets look at an example of a modular application written with the <a href="http://github.com/joelhooks/robotlegs-utilities-Modular">Robotlegs Modular Utility</a>. It is fairly useless, but covers the core concepts of what a modular application should be able to do.</p>
<h2>Modular Doodads: A Lame but Functional Example</h2>
<div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ModularDoodads_908075958"
			class="flashmovie"
			width="450"
			height="550">
	<param name="movie" value="http://joelhooks.com/examples/modularDoodads/ModularDoodads.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://joelhooks.com/examples/modularDoodads/ModularDoodads.swf"
			name="fm_ModularDoodads_908075958"
			width="450"
			height="550">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object></div>
<p><strong><a href="http://github.com/joelhooks/robotlegs-examples-ModularDoodads">The full source for this example can be found HERE...</a></strong></p>
<div class="note-block">It was noted in the comments that this gets sluggish after more than a few Doodads are added. This is a Flex invalidation issue. <a href="http://joelhooks.com/examples/modularDoodadsAS3/ModularDoodads.html">Here is the example in pure AS3 with MinimalComps (view source is enabled)</a></div>
<p>In this example you have three separate modules: the Shell, or the main application, a logging module that provides "console" output, and Doodads. Doodads are simple modules with not a whole lot of functionality. When you add a Doodad the shell creates a new Doodad and adds it to a container. The Doodads have a "request" button that will ask any other Doodads to change color. In addition to that, they have a close button to remove the Doodad. Above the Doodad container is a "trigger" button. This sends out an event that triggers a command on all of the Doodad modules (causing them to flash violently).</p>
<h3>ModularDoodadsContext.as</h3>

<div class="wp_codebox"><table><tr id="p5034"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p503code4"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ModularDoodadsContext <span style="color: #0066CC;">extends</span> ModuleContext
<span style="color: #66cc66;">&#123;</span>
    override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//map the modules so that instances will be properly supplied (injected) with an injector.</span>
        viewMap.<span style="color: #006600;">mapType</span><span style="color: #66cc66;">&#40;</span>LoggerModule<span style="color: #66cc66;">&#41;</span>;
        viewMap.<span style="color: #006600;">mapType</span><span style="color: #66cc66;">&#40;</span>DoodadModule<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        mediatorMap.<span style="color: #006600;">mapView</span><span style="color: #66cc66;">&#40;</span>ModularDoodads, ModuleDoodadsMediator<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The main shell application context context is doing a couple of things. As with the other modules within the application, this Context extends ModuleContext. ModuleContext will create the ModuleEventDispatcher (IModuleEventDispatcher) as well as a ModuleCommandMap that can be used to map commands that respond to events on the ModuleEventDispatcher. ModuleContext is a convenience mechanism.</p>
<p>Since the modules in this application are view components we can use the ViewMap to map their types. This facilitates injection into the modules when they are added to the stage. The reason for this will become clear as we look at one of these modules.</p>
<h3>LoggerModule.mxml</h3>

<div class="wp_codebox"><table><tr id="p5035"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code" id="p503code5"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Module xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
           xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
           xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span>
           <span style="color: #0066CC;">implements</span>=<span style="color: #ff0000;">&quot;org.robotlegs.utilities.modular.core.IModule&quot;</span>
           layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;75&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
            <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">robotlegs</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">IContext</span>;
            <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">robotlegs</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">IInjector</span>;
            <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">robotlegs</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">modular</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">IModule</span>;
            <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">robotlegs</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">modular</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">IModuleContext</span>;
&nbsp;
            <span style="color: #0066CC;">import</span> robotlegs.<span style="color: #006600;">examples</span>.<span style="color: #006600;">modulardoodads</span>.<span style="color: #006600;">modules</span>.<span style="color: #006600;">logger</span>.<span style="color: #006600;">skins</span>.<span style="color: #006600;">LoggingTextArea</span>;
&nbsp;
            protected <span style="color: #000000; font-weight: bold;">var</span> context:IModuleContext;
&nbsp;
            <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>mimeType=<span style="color: #ff0000;">'application/x-font'</span>, source=<span style="color: #ff0000;">&quot;assets/AnonPro.ttf&quot;</span>, fontName=<span style="color: #ff0000;">&quot;Anon&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> anon:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> messages:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addLoggingMessage<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">message</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">message</span> += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>;
                messages += <span style="color: #0066CC;">message</span>;
                scrollToMax<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> scrollToMax<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                messageDisplay.<span style="color: #006600;">validateNow</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                messageDisplay.<span style="color: #006600;">scroller</span>.<span style="color: #006600;">verticalScrollBar</span>.<span style="color: #006600;">value</span> = messageDisplay.<span style="color: #006600;">scroller</span>.<span style="color: #006600;">verticalScrollBar</span>.<span style="color: #006600;">maximum</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">/**
             * We need to initialize our context by setting the parent
             * injector for the module. This is actually injected by the
             * shell, so no need to worry about it!
            */</span>
            <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span>
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> parentInjector<span style="color: #66cc66;">&#40;</span>value:IInjector<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                context = <span style="color: #000000; font-weight: bold;">new</span> LoggerModuleContext<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, value<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dispose<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                context.<span style="color: #006600;">dispose</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                context = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>s:TextArea
        id=<span style="color: #ff0000;">&quot;messageDisplay&quot;</span>
        fontFamily=<span style="color: #ff0000;">&quot;Anon&quot;</span>
        fontSize=<span style="color: #ff0000;">&quot;12&quot;</span>
        <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span>
        <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{messages}&quot;</span>
        skinClass=<span style="color: #ff0000;">&quot;robotlegs.examples.modulardoodads.modules.logger.skins.LoggingTextArea&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Module<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Looking at the LoggerModule.mxml it is important to note that it implements the org.robotlegs.utilities.modular.core.IModule interface. This provides a contract to ensure that we supply the appropriate API to initialize the module. The IModule interface provides a setter for the parentInjector as well as a dispose() method that we can use to cleanup the module when it is removed. The key here is the setter for the parentInjector that supplies an injector to the module. This setter actually creates the context or the module and passes the injector into the context. As you will recall in the ModularDoodadContext above, the LoggerModule was mapped with the ViewMap. This means that when it is added to the stage its dependencies are injected. parentInjector is marked with the [Inject] metadata so the injector is automatically provided to the module. The context will then use that injector and create a child injector.</p>
<h5>Child Injectors</h5>
<p>A child injector is a new concept in Robotlegs 1.1. It is a powerful tool. When the parentInjector is set, the module context uses it to create a child injector. This child injector has a reference to its parent and the parent's injection mappings. This means that if you don't create a mapping in the child injector it will supply the injection a mapped within the parent (or grandparent). The parent has no reference at all to the child, and doesn't even know that it exists so if you create mappings in a child injector they are not reflected up the injector chain to ancestors. If you create a mapping that is identical to a mapping within an injector's family tree, the first mapping is honored and the injector will not check with its ancestors to see if the mapping exists.</p>
<p>Through this mechanism of child injectors we are able to map an event dispatcher within the top level application context that can then be shared amongst any number of other contexts providing that they are able to create and use a child injector. This is the core of how these modules are able to communicate with one another. We create the IModuleEventDispatcher in the shell and all sub-modules now have access to it through their injector. As long as you don't map a IModuleEventDispatcher with the child, any injections that call for it will be supplied with the original dispatcher from the parent injector.</p>
<p> Now what? For the most part, you develop modules <a href="http://wiki.github.com/robotlegs/robotlegs-framework/best-practices">as you would any other Robotlegs application</a>. The Modular Utility does provide one other convenient mechanism to help save you on some typing. That is the ModuleMediator.</p>
<h3>DoodadModuleMediator.as</h3>

<div class="wp_codebox"><table><tr id="p5036"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p503code6"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DoodadModuleMediator <span style="color: #0066CC;">extends</span> ModuleMediator
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> view:DoodadModule;
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> madeRequest:<span style="color: #0066CC;">Boolean</span>;
&nbsp;
    override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onRegister<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        addViewListener<span style="color: #66cc66;">&#40;</span>DoodadModuleEvent.<span style="color: #006600;">DO_STUFF_REQUESTED</span>, handleDoStuffRequested, DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>;
        addViewListener<span style="color: #66cc66;">&#40;</span>DoodadModuleEvent.<span style="color: #006600;">REMOVE</span>, handleRemove<span style="color: #66cc66;">&#41;</span>;
        addModuleListener<span style="color: #66cc66;">&#40;</span>DoodadModuleEvent.<span style="color: #006600;">DO_STUFF_REQUESTED</span>, handleDoStuffRequest, DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>;
        addContextListener<span style="color: #66cc66;">&#40;</span>DoodadModuleEvent.<span style="color: #006600;">FLASH_YOUR_DOODAD</span>, handleDoodadFlashRequest<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleRemove<span style="color: #66cc66;">&#40;</span>event:DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        dispatchToModules<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LoggingEvent<span style="color: #66cc66;">&#40;</span>LoggingEvent.<span style="color: #0066CC;">MESSAGE</span>, <span style="color: #ff0000;">&quot;Removing DoodadModule&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        dispatchToModules<span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>;
        view.<span style="color: #006600;">dispose</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleDoStuffRequested<span style="color: #66cc66;">&#40;</span>event:DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        madeRequest = <span style="color: #000000; font-weight: bold;">true</span>;
        dispatchToModules<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LoggingEvent<span style="color: #66cc66;">&#40;</span>LoggingEvent.<span style="color: #0066CC;">MESSAGE</span>, <span style="color: #ff0000;">&quot;DoodadModule made request...&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        moduleDispatcher.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleDoStuffRequest<span style="color: #66cc66;">&#40;</span>event:DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>madeRequest<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            view.<span style="color: #0066CC;">color</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>0xFFFFFF;
            dispatchToModules<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LoggingEvent<span style="color: #66cc66;">&#40;</span>LoggingEvent.<span style="color: #0066CC;">MESSAGE</span>, <span style="color: #ff0000;">&quot;DoodadModule changed color: &quot;</span> + view.<span style="color: #0066CC;">color</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        madeRequest = <span style="color: #000000; font-weight: bold;">false</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleDoodadFlashRequest<span style="color: #66cc66;">&#40;</span>event:DoodadModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        view.<span style="color: #006600;">flashIt</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The DoodadModuleMediator extends ModuleMediator. The ModuleMediator provides basic injections for the ModuleCommandMap and the ModuleEventDispatcher. ModuleMediator also provides some convenience with a bit of syntactic sugar to make it easy to dispatch events to the ModuleEventDispatcher. The dispatchToModules() method sends events over the ModuleEventDispatcher in contrast to the dispatch() method which sends events over the EventDispatcher that is local to the context. Additionally you are provided with addModuleListener() that makes it easy to add a listener for an event type that is expected to be dispatched from another module (including the shell). These methods simply abstract the eventMap.mapListener() method, which in turn is abstracting eventDispatcher.addEventListener(). You have nothing if not options when it comes to adding a listener within a mediator!</p>
<h2>Modular Application Development in Flex... Some Caveats</h2>
<p>Possibly the biggest gotcha with modular application development is managing memory. With a typical application you are dealing with a single "module" - the application itself. You do not typically attempt to unload your entire application from memory. Simply refreshing the page or navigating away more effectively does this. We do try to prevent memory leaks diligently (right?) to provide our users with the smoothest possible experience, but this is different from trying to release all of the memory the application uses at runtime. Modules, on the other hand, can come into existence at runtime at any point during the lifecycle of your application. On the flip side of that is that the modules should be able to completely unload and release all of the memory that they have used.</p>
<p>There are a host of "tricks" to getting modules out of memory. This <a href="http://blogs.adobe.com/tomsugden/2010/02/how_to_unload_modules_effectively.html">article</a> is a good overview of the major ones. In addition to these sneaky memory peggers, you will also want to carefully ensure that your modules release references and dispose of objects properly.</p>
<p>The Modular Utility makes every effort to provide mechanisms for disposing of your modules, but when it gets down to it most of that responsibility will be left up to you. If you notice that Robotlegs or the Modular Utility is preventing a module from unloading <b>please let me know</b> so that I can address it as soon as possible. The end goal is to provide a robust tool for developing Robotlegs applications with modules. The Modular Utility is currently very modest, but what it isn't is a solution looking for a problem. As it grows it will be in response to real problems, and your feedback and use is critical to meeting that goal.</p>
<h3>The bits you'll need...</h3>
<p><a href="http://github.com/joelhooks/robotlegs-utilities-Modular">Robotlegs Modular Utility (my fork)</a><br />
<a href="http://github.com/joelhooks/robotlegs-examples-ModularDoodads">The full source for this example</a><br />
<a href="http://www.robotlegs.org">Robotlegs AS3</a></p>
<h3>On a related note...</h3>
<p>I recently had the pleasure of writing a full 22 pages on Robotlegs in the upcoming <a href="http://www.manning.com/ahmed2/">Flex 4 in Action from Manning</a>. It is a great book overall and if you'd like to learn more about Robotlegs (or Flex 4 in general) then I highly recommend it.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2010/05/02/modular-robotlegs/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>SuperPanelPlus: Resizable Flex Panel Component with Accessible Styling</title>
		<link>http://joelhooks.com/2008/05/26/superpanelplus-resizable-flex-panel-component-with-accessible-styling/</link>
		<comments>http://joelhooks.com/2008/05/26/superpanelplus-resizable-flex-panel-component-with-accessible-styling/#comments</comments>
		<pubDate>Mon, 26 May 2008 20:38:02 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://joelhooks.com/2008/05/26/superpanelplus-resizable-flex-panel-component-with-accessible-styling/</guid>
		<description><![CDATA[The SuperPanel is an excellent component created by Wietse Veenstra. The styling is all hard-coded,  and I need to be able to change this. It also hard-codes the event that is triggered on close, and I wanted to be able to control this. So I added the appropriate meta-tags and properties to enable these options. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.wietseveenstra.nl/blog/2007/04/flex-superpanel-v15/">SuperPanel</a> is an excellent component created by <a href="http://www.wietseveenstra.nl/blog/about/">Wietse Veenstra</a>. The styling is all hard-coded,  and I need to be able to change this. It also hard-codes the event that is triggered on close, and I wanted to be able to control this. So I added the appropriate meta-tags and properties to enable these options. Here is the result, link to the source is at the bottom:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_SuperPanelPlus_905436498"
			class="flashmovie"
			width="500"
			height="400">
	<param name="movie" value="http://joelhooks.com/examples/superPanelPlus/SuperPanelPlus.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://joelhooks.com/examples/superPanelPlus/SuperPanelPlus.swf"
			name="fm_SuperPanelPlus_905436498"
			width="500"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><a href="http://joelhooks.com/examples/superPanelPlus/srcview/">Source is here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/05/26/superpanelplus-resizable-flex-panel-component-with-accessible-styling/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Using the Senocular AS3 TransformTool in Flex</title>
		<link>http://joelhooks.com/2008/04/20/using-the-senocular-as3-transformtool-in-flex/</link>
		<comments>http://joelhooks.com/2008/04/20/using-the-senocular-as3-transformtool-in-flex/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 17:01:31 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://joelhooks.com/2008/04/20/using-the-senocular-as3-transformtool-in-flex/</guid>
		<description><![CDATA[Hey,I am so interested about that you had ever used the ‘TransformTool’ library in your Flex project. But there is little examples showing how to use it in flex, Would you please share some example about how to use ‘TransformTool’ in Flex? I have tried as such a way: but it failed at line canvas.addChild(defaultTool); [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Hey,I am so interested about that you had ever used the ‘TransformTool’ library in your Flex project. But there is little examples showing how to use it in flex, Would you please share some example about how to use ‘TransformTool’ in Flex? I have tried as such a way:</p>
<p>but it failed at line<br />
canvas.addChild(defaultTool);<br />
Can you give any hints? Thanks.</p></blockquote>
<p>Like most pure AS3 display classes, the <a href="http://www.senocular.com/demo/TransformToolAS3/TransformTool.html">TransformTool</a> needs to be added to a UIComponent wrapper to function properly in Flex.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_TransformToolFlexExample_1275678054"
			class="flashmovie"
			width="490"
			height="500">
	<param name="movie" value="http://joelhooks.com/examples/transformTool/TransformToolFlexExample.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://joelhooks.com/examples/transformTool/TransformToolFlexExample.swf"
			name="fm_TransformToolFlexExample_1275678054"
			width="490"
			height="500">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><a href="http://joelhooks.com/examples/transformTool">Source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/04/20/using-the-senocular-as3-transformtool-in-flex/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Christian Cantrell&#039;s ever-growing selection of useful Actionscript 3/AIR libraries.</title>
		<link>http://joelhooks.com/2008/03/23/christian-cantrells-ever-growing-selection-of-useful-actionscript-3air-libraries/</link>
		<comments>http://joelhooks.com/2008/03/23/christian-cantrells-ever-growing-selection-of-useful-actionscript-3air-libraries/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 04:05:13 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://joelhooks.com/2008/03/23/christian-cantrells-ever-growing-selection-of-useful-actionscript-3air-libraries/</guid>
		<description><![CDATA[Here's the full list of what he has on Google Code. The CoreLib is essential, but he's been busy writing useful libraries for AIR. I've used the notification library, which has some great features and makes notifications on the desktop sensible. The exchange library is interesting, for sure. They are all worth checking out. There [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/u/christian.cantrell/">Here's the full list of what he has on Google Code</a>.</p>
<p>The CoreLib is essential, but he's been busy writing useful libraries for AIR. I've used the notification library, which has some great features and makes notifications on the desktop sensible. The exchange library is interesting, for sure. They are all worth checking out.</p>
<p>There are also a number of interesting example applications using AIR, including a <a href="http://code.google.com/p/snakeeye/">motion detection application</a>, an <a href="http://code.google.com/p/s3e/">Amazon S3 interface</a>, a <a href="http://code.google.com/p/screenprotectionfactor/">screen saver</a>, and an <a href="http://code.google.com/p/lineup/">MS Exchange calendar</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/03/23/christian-cantrells-ever-growing-selection-of-useful-actionscript-3air-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>KitchenSync &#8211; open-source Actionscript 3 tweening and timing animation library</title>
		<link>http://joelhooks.com/2008/01/22/kitchensync-open-source-actionscript-3-tweening-and-timing-animation-library/</link>
		<comments>http://joelhooks.com/2008/01/22/kitchensync-open-source-actionscript-3-tweening-and-timing-animation-library/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 17:26:44 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://joelhooks.com/2008/01/22/kitchensync-open-source-actionscript-3-tweening-and-timing-animation-library/</guid>
		<description><![CDATA[Mims Wright has released an open-source animation library for Actionscript 3. This has a lot of promise. From the author: KitchenSync was designed for developers who want a smart way to handle animation or other time-based functionality with code. Written from the ground up in ActionScript 3.0, KitchenSync relies on smart object-oriented architecture rather than [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.partlyhuman.com/blog/mims/introducing-kitchensync-animation-library-for-as3"><img src="http://69.164.207.135/wp-content/uploads/2008/01/kslogo.png" alt="KitchenSync" /></a></p>
<p align="left">Mims Wright has released <a href="http://code.google.com/p/kitchensynclib/">an open-source animation library for Actionscript 3</a>. This has a lot of promise. From the author:</p>
<blockquote>
<p align="left">KitchenSync was designed for developers who want a smart way to handle animation or other time-based functionality with code. Written from the ground up in ActionScript 3.0, KitchenSync relies on smart object-oriented architecture rather than complicated shorthand. It includes a number of features and shortcuts, such as the <tt>clone()</tt> method, that save effort for developers. KitchenSync makes extensive use of events and informative runtime errors and is quite flexible when it comes to extending the functionality.</p>
</blockquote>
<p align="left">&nbsp;</p>
<blockquote></blockquote>
<p align="left"> This philosophy makes me think that <a href="http://www.partlyhuman.com/blog/mims/introducing-kitchensync-animation-library-for-as3">KitchenSync</a> will fit in nicely with <a href="http://puremvc.org/">pureMVC</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/01/22/kitchensync-open-source-actionscript-3-tweening-and-timing-animation-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
	</channel>
</rss>
