<?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>digitaldogbyte.com &#187; ActionScript</title>
	<atom:link href="http://www.digitaldogbyte.com/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitaldogbyte.com</link>
	<description>powered by kilobits n' bytes</description>
	<lastBuildDate>Sat, 16 Jul 2011 03:01:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Robotlegs using a shared eventdispatcher between multiple contexts</title>
		<link>http://www.digitaldogbyte.com/2010/08/29/robotlegs-using-a-shared-eventdispatcher-between-multiple-contexts/</link>
		<comments>http://www.digitaldogbyte.com/2010/08/29/robotlegs-using-a-shared-eventdispatcher-between-multiple-contexts/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 02:17:47 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=133</guid>
		<description><![CDATA[My last couple posts discussed two different methods of writing modular applications using the Robotlegs framework. This post will demonstrate yet another method of writing modular applications in Robotlegs using a shared eventDispatcher between the modules. This approach requires the creation of a getter method for the eventDispatcher from the Application Shell&#8217;s context. The eventDispatcher [...]]]></description>
			<content:encoded><![CDATA[<p>My last couple posts discussed two different methods of writing modular applications using the Robotlegs framework. This post will demonstrate yet another method of writing modular applications in Robotlegs using a shared eventDispatcher between the modules.</p>
<p>This approach requires the creation of a getter method for the eventDispatcher from the Application Shell&#8217;s context. The eventDispatcher is then injected into the contexts of each module using:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// injects the application shell's eventDispatcher into the module's context</span>
injector<span style="color: #000066; font-weight: bold;">.</span>mapValue<span style="color: #000000;">&#40;</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">,</span> Application<span style="color: #000066; font-weight: bold;">.</span>application<span style="color: #000066; font-weight: bold;">.</span>applicationEventDispatcher<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;ApplicationEventDispatcher&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>The &#8220;ApplicationEventDispatcher&#8221; is then used to listen to events and to dispatch events throughout the entire application.</p>
<p>Here is the <a href="http://www.digitaldogbyte.com/downloads/rl_shared_eventdispatcher/RL_Modular_Multiple_Contexts_Shared_Eventdispatcher.html" target="_blank">demo</a> and the <a href="http://www.digitaldogbyte.com/downloads/rl_shared_eventdispatcher/srcview/index.html" target="_blank">source</a> code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2010/08/29/robotlegs-using-a-shared-eventdispatcher-between-multiple-contexts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Robotlegs modular application with multiple contexts</title>
		<link>http://www.digitaldogbyte.com/2010/08/20/robotlegs-modular-application-with-multiple-contexts/</link>
		<comments>http://www.digitaldogbyte.com/2010/08/20/robotlegs-modular-application-with-multiple-contexts/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 14:16:20 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=113</guid>
		<description><![CDATA[My previous post demonstrated modular programming in the Robotlegs framework using the Robotlegs modular utilities. This post will discuss a workaround that I came up with to handle inter-context communication between modules before the Robotlegs Modular Utilities were released. The benefits of using this workaround is that you can have modules in their own encapsulated [...]]]></description>
			<content:encoded><![CDATA[<p>My previous post demonstrated modular programming in the <a href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> framework using the Robotlegs modular utilities. This post will discuss a workaround that I came up with to handle inter-context communication between modules before the <a href="http://github.com/joelhooks/robotlegs-utilities-Modular" target="_blank">Robotlegs Modular Utilities</a> were released.</p>
<p>The benefits of using this workaround is that you can have modules in their own encapsulated contexts, the disadvantage is that this solution is not very scalable if you have lots of events that need to be mapped between the contexts.</p>
<p>The basic idea is to create a getter for the _eventDispatcher property in the context of each module. Once the root application has fired the creationComplete event, the handler for creationComplete needs to use the getters so that the root application can perform the necessary event mapping which will allow the two modules to communicate.</p>
<p>Here is the <a href="http://www.digitaldogbyte.com/downloads/rl_modular_multiple_contexts_demo/RL_Modular_Multiple_Contexts.html" target="_blank">demo</a> and the <a href="http://www.digitaldogbyte.com/downloads/rl_modular_multiple_contexts_demo/srcview/index.html" target="_blank">source code</a>.</p>
<p>I&#8217;ve added inline comments within the source code explaining how to map the events between the modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2010/08/20/robotlegs-modular-application-with-multiple-contexts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Robotlegs Modular Utilities Tutorial</title>
		<link>http://www.digitaldogbyte.com/2010/08/17/robotlegs-modular-utilities-tutorial/</link>
		<comments>http://www.digitaldogbyte.com/2010/08/17/robotlegs-modular-utilities-tutorial/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 05:05:56 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=84</guid>
		<description><![CDATA[In the past year I have been using the Robotlegs MVCS framework for AS3 extensively; one of the bigger challenges that I encountered was creating an application with several self contained modules that needed to communicate with each other. Joel Hooks &#038; Stray, a couple of the main contributors to the Robotlegs framework created a [...]]]></description>
			<content:encoded><![CDATA[<p>In the past year I have been using the <a href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> MVCS framework for AS3 extensively; one of the bigger challenges that I encountered was creating an application with several self contained modules that needed to communicate with each other. Joel Hooks &#038; Stray, a couple of the main contributors to the Robotlegs framework created a modular utility which resolves this particular issue within the Robotlegs framework. Joel Hooks also has a very informative post and a tutorial / demo posted on his <a href="http://joelhooks.com/2010/05/02/modular-robotlegs/" target="_blank">blog</a>.</p>
<p>I created a very simple demo which I used to learn how to implement the Robotlegs Modular Utility and this post will provide a step by step walkthrough of how to setup a modular Robotlegs project in Flex 3.5. This tutorial is for people that have some knowledge of the Robotlegs framework &#038; Flex. You can learn more about Robotlegs at the Robotlegs <a href="http://knowledge.robotlegs.org/" target="_blank">knowledgebase</a>.</p>
<p>To get started you will need the following:</p>
<ul>
<li>Flex Builder 3 or Flash Builder 4 with the Flex 3.5 SDK</li>
<li><a href="http://github.com/joelhooks/robotlegs-utilities-Modular" target="_blank">Robotlegs framework &#038; Robotlegs Modular Utility</a></li>
</ul>
<p>The simple demo application features two modules and an application shell. The first module is a button which will send the timestamp from the Date Object&#8217;s getTime() method to the second module, which will then display the timestamp. The application shell simple holds the two modules.</p>
<p>Here is the <a href="http://www.digitaldogbyte.com/downloads/rl_modular_demo/RL_Modular_Demo.html" target="_blank">demo</a> &#038; <a href="http://www.digitaldogbyte.com/downloads/rl_modular_demo/srcview/index.html" target="_blank">source code</a> for those of you that don&#8217;t want to read the whole tutorial. The links are provided again at the end of the posting for those that want to finish reading the tutorial.</p>
<p>The first step is to create a new project in Flex and then to copy the files for the Robotlegs Modular Utilities into the src folder of your project and then to create the project structure for the sample application. The project tree in Flex should look like the following image after you have completed setting up the project.</p>
<p><img src="http://www.digitaldogbyte.com/images/rl_modular_demo/rl_modular_project_tree.png" alt="Flex Project Structure" /></p>
<p><strong>Part 1 &#8211; setting up the first module &#8211; ButtonModule</strong></p>
<p>Now that the project has been setup, we&#8217;ll begin with creating the view for the ButtonModule; simply create a new MXML Component named ButtonModule.mxml under the buttonModule folder.</p>
<p>Code for ButtonModule.mxml:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IModuleContext<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IInjector<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> context<span style="color: #000066; font-weight: bold;">:</span>IModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
			<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> parentInjector<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span>IInjector<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
			<span style="color: #000000;">&#123;</span>
				context = <span style="color: #0033ff; font-weight: bold;">new</span> ButtonModuleContext<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;myButton&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>The ButtonModule.mxml view defines the UI of the ButtonModule and also initializes the ButtonModuleContext by specifying the contextView and the injector when<br />
the ButtonModule view is instantiated. The contextView is specifies the view that scopes the ModuleContext; i.e. the ModuleContext is only able to map injections/mediators within the contextView. The injector is used to insert  classes into any other classes that as long as both the target and source classes are mapped within the scope of the ModuleContext.</p>
<p>Next, we need to create the a context for the ButtonModule; create an ActionScript Class named ButtonModuleContext.as with a superclass of ModuleContext under the buttonModule folder.</p>
<p>Code for ButtonModuleContext.as:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>buttonModule
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>buttonModule<span style="color: #000066; font-weight: bold;">.</span>views<span style="color: #000066; font-weight: bold;">.</span>ButtonModuleMediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IInjector<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ButtonModuleContext <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleContext
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ButtonModuleContext<span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">,</span> injector<span style="color: #000066; font-weight: bold;">:</span>IInjector<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> injector<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;button module context&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			mediatorMap<span style="color: #000066; font-weight: bold;">.</span>mapView<span style="color: #000000;">&#40;</span>ButtonModule<span style="color: #000066; font-weight: bold;">,</span> ButtonModuleMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The ButtonModuleContext simply maps the ButtonModule view to the ButtonModuleMediator. The mediator acts as the &#8220;code-behind&#8221; for the view; it is often used to map event listeners to event handlers for the view and is often contains business logic &#038; presentation logic for view.</p>
<p>The mediator is the last piece required to complete the ButtonModule; create an ActionScript Class named ButtonModuleMediator.as with a superclass of ModuleMediator under the buttonModule/views folder.</p>
<p>Code for ButtonModuleMediator.as:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>buttonModule<span style="color: #000066; font-weight: bold;">.</span>views
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>buttonModule<span style="color: #000066; font-weight: bold;">.</span>ButtonModule<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>LabelModuleEvent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleMediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ButtonModuleMediator <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleMediator
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000066; font-weight: bold;">:</span>ButtonModule<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ButtonModuleMediator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onRegister<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			view<span style="color: #000066; font-weight: bold;">.</span>myButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;display timestamp&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			addViewListener<span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> onButtonClicked<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onButtonClicked<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">date</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			dispatchToModules<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> LabelModuleEvent<span style="color: #000000;">&#40;</span>LabelModuleEvent<span style="color: #000066; font-weight: bold;">.</span>DISPLAY_MESSAGE<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">date</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In the ButtonModuleMediator, we are telling the mediator to listen for a mouse click on the view and handle the mouse click by invoking the onButtonClicked method. The onButtonClicked method then invokes the dispatchToModules method (inherited from ModuleMediator) which checks to see which module has a listener for the LabelModuleEvent.DISPLAY_MESSAGE event and then dispatches the event to that module.</p>
<p>At this point, your project explorer should look like this:</p>
<p><img src="http://www.digitaldogbyte.com/images/rl_modular_demo/rl_modular_project_tree_part1.png" alt="Flex Project Structure with ButtonModule" /></p>
<p><strong>Part 2 &#8211; setting up the second module &#8211; LabelModule</strong></p>
<p>The steps for creating the LabelModule are nearly identical to the steps taken to create the ButtonModule. You will need to create a view, context and mediator.</p>
<p>Code for LabelModule view &#8211; LabelModule.mxml:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IModuleContext<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IInjector<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> context<span style="color: #000066; font-weight: bold;">:</span>IModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
			<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> parentInjector<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span>IInjector<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
			<span style="color: #000000;">&#123;</span>
				context = <span style="color: #0033ff; font-weight: bold;">new</span> LabelModuleContext<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;myLabel&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Code for LabelModule context &#8211; LabelModuleContext.as with a superclass of ModuleContext:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000066; font-weight: bold;">.</span>LabelModuleMediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IInjector<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LabelModuleContext <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleContext
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LabelModuleContext<span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">,</span> injector<span style="color: #000066; font-weight: bold;">:</span>IInjector<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> injector<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;label module context&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			mediatorMap<span style="color: #000066; font-weight: bold;">.</span>mapView<span style="color: #000000;">&#40;</span>LabelModule<span style="color: #000066; font-weight: bold;">,</span> LabelModuleMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Code for LabelModule mediator &#8211; LabelModuleMediator.as with a superclass of ModuleMediator in the labelModule/views folder:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>view
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>LabelModule<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>LabelModuleEvent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleMediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LabelModuleMediator <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleMediator
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000066; font-weight: bold;">:</span>LabelModule<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LabelModuleMediator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onRegister<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			setMessage<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;timestamp will display here&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			eventMap<span style="color: #000066; font-weight: bold;">.</span>mapListener<span style="color: #000000;">&#40;</span>moduleDispatcher<span style="color: #000066; font-weight: bold;">,</span> LabelModuleEvent<span style="color: #000066; font-weight: bold;">.</span>DISPLAY_MESSAGE<span style="color: #000066; font-weight: bold;">,</span> onDisplayMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onDisplayMessage<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>LabelModuleEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					setMessage<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span>
				<span style="color: #000000;">&#123;</span>
					setMessage<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;event data was null&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span>
			<span style="color: #000000;">&#123;</span>
				setMessage<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;event was null&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> setMessage<span style="color: #000000;">&#40;</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			view<span style="color: #000066; font-weight: bold;">.</span>myLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">;</span>	
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In the LabelModuleMediator you will notice that we are register the onDisplayMessage event handler for the LabelModuleEvent.DISPLAY_MESSAGE event.</p>
<p>To allow communication between the ButtonModule and LabelModule, we need to create a custom event. I decided to create the event as the LabelModuleEvent since the LabelModule is the module that will be listening and handling the event, while the ButtonModule only needs to dispatch the event.</p>
<p>The event can be created by adding a new ActionScript class named LabelModuleEvent.as with a superclass of Event in the labelModule/events folder.</p>
<p>Code for LabelModuleEvent.as:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>events
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LabelModuleEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> static const DISPLAY_MESSAGE<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;displayMessage&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _data<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LabelModuleEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			_data = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> LabelModuleEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _data<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>		
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>At this point, your project explorer should look like this:</p>
<p><img src="http://www.digitaldogbyte.com/images/rl_modular_demo/rl_modular_project_tree_part2.png" alt="Flex Project Structure with LabelModule" /></p>
<p><strong>Part 3 &#8211; setting up the application shell &#8211; ApplicationShell</strong></p>
<p>You will need to create a view, context and mediator for the ApplicationShell.</p>
<p>Code for ApplicationShell view &#8211; ApplicationShell.mxml:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> preinitialize=<span style="color: #990000;">&quot;preinit();&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>buttonModule=<span style="color: #990000;">&quot;com.digitaldogbyte.buttonModule.*&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>labelModule=<span style="color: #990000;">&quot;com.digitaldogbyte.labelModule.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _context<span style="color: #000066; font-weight: bold;">:</span>ApplicationShellContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> preinit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
			<span style="color: #000000;">&#123;</span>
				_context = <span style="color: #0033ff; font-weight: bold;">new</span> ApplicationShellContext<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>buttonModule<span style="color: #000066; font-weight: bold;">:</span>ButtonModule id=<span style="color: #990000;">&quot;buttonModule&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>labelModule<span style="color: #000066; font-weight: bold;">:</span>LabelModule id=<span style="color: #990000;">&quot;labelModule&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Code for the ApplicationShell context &#8211; ApplicationShellContext.as with superclass of ModuleContext:</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>applicationShell
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>applicationShell<span style="color: #000066; font-weight: bold;">.</span>views<span style="color: #000066; font-weight: bold;">.</span>ApplicationShellMediator<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>buttonModule<span style="color: #000066; font-weight: bold;">.</span>ButtonModule<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>labelModule<span style="color: #000066; font-weight: bold;">.</span>LabelModule<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>IInjector<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleContext<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ApplicationShellConteThext <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleContext
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ApplicationShellContext<span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObjectContainer</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> autoStartup<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> parentInjector<span style="color: #000066; font-weight: bold;">:</span>IInjector=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">applicationDomain</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ApplicationDomain</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span>contextView<span style="color: #000066; font-weight: bold;">,</span> autoStartup<span style="color: #000066; font-weight: bold;">,</span> parentInjector<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">applicationDomain</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;application shell context&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			viewMap<span style="color: #000066; font-weight: bold;">.</span>mapType<span style="color: #000000;">&#40;</span>ButtonModule<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			viewMap<span style="color: #000066; font-weight: bold;">.</span>mapType<span style="color: #000000;">&#40;</span>LabelModule<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			mediatorMap<span style="color: #000066; font-weight: bold;">.</span>mapView<span style="color: #000000;">&#40;</span>ApplicationShell<span style="color: #000066; font-weight: bold;">,</span> ApplicationShellMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Code for the ApplicationShell mediator &#8211; ApplicationShellMediator.as with superclass of ModuleMediator within the applicationShell/views folder:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>applicationShell<span style="color: #000066; font-weight: bold;">.</span>views
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>applicationShell<span style="color: #000066; font-weight: bold;">.</span>ApplicationShell<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>utilities<span style="color: #000066; font-weight: bold;">.</span>modular<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>ModuleMediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ApplicationShellMediator <span style="color: #0033ff; font-weight: bold;">extends</span> ModuleMediator
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000066; font-weight: bold;">:</span>ApplicationShell<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ApplicationShellMediator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>		
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The final project structure should look like this:</p>
<p><img src="http://www.digitaldogbyte.com/images/rl_modular_demo/rl_modular_project_tree_part3.png" alt="Flex Project Structure with ApplicationShell" /></p>
<p><a href="http://www.digitaldogbyte.com/downloads/rl_modular_demo/RL_Modular_Demo.html" target="_blank">Demo</a> &#038; <a href="http://www.digitaldogbyte.com/downloads/rl_modular_demo/srcview/index.html" target="_blank">source</a> files for the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2010/08/17/robotlegs-modular-utilities-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQLite Encryption in AIR 1.5</title>
		<link>http://www.digitaldogbyte.com/2009/02/10/sqlite-encryption-in-air-15/</link>
		<comments>http://www.digitaldogbyte.com/2009/02/10/sqlite-encryption-in-air-15/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 03:28:44 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=9</guid>
		<description><![CDATA[The Adobe AIR runtime includes a SQLite database so that you can create data driven applications. The following are the default locations for the SQLite database: Mac OS X: /Users/&#60;userName&#62;/Library/Preferences/&#60;applicationName&#62;/Local Store/&#60;databaseFileName&#62;.db Windows: C:\Documents and Settings\&#60;userName&#62;\Application Data\&#60;applicationName&#62;\Local Store\&#60;databaseFileName&#62;.db Adobe AIR 1.5 introduces a feature to encrypt the SQLite database so that you can secure the contents [...]]]></description>
			<content:encoded><![CDATA[<p>The Adobe AIR runtime includes a <a href="http://www.sqlite.org/index.html" title="sqlite.org" target="_blank">SQLite</a> database so that you can create data driven applications.</p>
<p>The following are the default locations for the SQLite database:</p>
<p>Mac OS X:</p>
<p>/Users/&lt;userName&gt;/Library/Preferences/&lt;applicationName&gt;/Local Store/&lt;databaseFileName&gt;.db</p>
<p>Windows:</p>
<p>C:\Documents and Settings\&lt;userName&gt;\Application Data\&lt;applicationName&gt;\Local Store\&lt;databaseFileName&gt;.db</p>
<p>Adobe AIR 1.5 introduces a feature to encrypt the SQLite database so that you can secure the contents of database. This is could come in handy if you are writing an application that stores information such as customer contact data.</p>
<p>The <a href="http://livedocs.adobe.com/flex/3/langref/flash/data/SQLConnection.html#open()" title="Open Method" target="_blank">Open</a> method and the <a href="http://livedocs.adobe.com/flex/3/langref/flash/data/SQLConnection.html#openAsync()" title="OpenAsync Method" target="_blank">OpenAsync</a> method of the <a href="http://livedocs.adobe.com/flex/3/langref/flash/data/SQLConnection.html" title="SQLConnection Class" target="_blank">SQLConnection</a> class include an encryptionKey parameter; this parameter tells AIR to encrypt the database file.</p>
<p>The code sample below shows you how to create / open an encrypted SQLite database. Links to an example application &amp; code can be found at the end of this article.</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>util<span style="color: #000066; font-weight: bold;">.</span>Encryption<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dbConn<span style="color: #000066; font-weight: bold;">:</span>SQLConnection<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dbFile<span style="color: #000066; font-weight: bold;">:</span>File<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dbKey<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	dbKey = Encryption<span style="color: #000066; font-weight: bold;">.</span>retrieveKey<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	dbFile = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;EncryptionExample.db&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dbFile<span style="color: #000066; font-weight: bold;">.</span>createDirectory<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	dbConn = <span style="color: #0033ff; font-weight: bold;">new</span> SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dbConn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SQLEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">OPEN</span><span style="color: #000066; font-weight: bold;">,</span> handleDbOpen<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dbConn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SQLErrorEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ERROR</span><span style="color: #000066; font-weight: bold;">,</span> handleDbError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// by passing in the dbKey variable as the encryptionKey parameter we are telling AIR to encrypt the SQLite database</span>
	dbConn<span style="color: #000066; font-weight: bold;">.</span>openAsync<span style="color: #000000;">&#40;</span>dbFile<span style="color: #000066; font-weight: bold;">,</span> SQLMode<span style="color: #000066; font-weight: bold;">.</span>CREATE<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1024</span><span style="color: #000066; font-weight: bold;">,</span> dbKey<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Let&#8217;s take a look at the Encryption class to see how the dbKey ByteArray is created. The dbKey value is assigned the return value of the retrieveKey method from the Encryption class. The retrieveKey method checks to see if a key already exists in the application&#8217;s EncryptedLocalStore. If the key already exists the retrieveKey method will return the existing key, however if the key does not exist; the generateKey method is called to create a key.</p>
<p>The generateKey method uses the <a href="http://code.google.com/p/as3crypto/" title="as3crypto library" target="_blank">as3crypto</a> library&#8217;s Random type to create a key. This key is required to read &amp; write to the encrypted database.</p>

<div class="wp_syntax"><table><tr><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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>digitaldogbyte<span style="color: #000066; font-weight: bold;">.</span>util
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>crypto<span style="color: #000066; font-weight: bold;">.</span>Crypto<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>crypto<span style="color: #000066; font-weight: bold;">.</span>prng<span style="color: #000066; font-weight: bold;">.</span>Random<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>crypto<span style="color: #000066; font-weight: bold;">.</span>symmetric<span style="color: #000066; font-weight: bold;">.</span>AESKey<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>crypto<span style="color: #000066; font-weight: bold;">.</span>symmetric<span style="color: #000066; font-weight: bold;">.</span>ECBMode<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>crypto<span style="color: #000066; font-weight: bold;">.</span>symmetric<span style="color: #000066; font-weight: bold;">.</span>ICipher<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>hurlant<span style="color: #000066; font-weight: bold;">.</span>util<span style="color: #000066; font-weight: bold;">.</span>Hex<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>EncryptedLocalStore<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ByteArray</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Encryption
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> _key<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> generateKey<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// create key - write to encrypted local store</span>
			_key = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">random</span><span style="color: #000066; font-weight: bold;">:</span>Random = <span style="color: #0033ff; font-weight: bold;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">random</span><span style="color: #000066; font-weight: bold;">.</span>nextBytes<span style="color: #000000;">&#40;</span>_key<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>EncryptedLocalStore<span style="color: #000066; font-weight: bold;">.</span>setItem<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;key&quot;</span><span style="color: #000066; font-weight: bold;">,</span>_key<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> retrieveKey<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// try to retrieve key from encrypted local store</span>
			_key = flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>EncryptedLocalStore<span style="color: #000066; font-weight: bold;">.</span>getItem<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;key&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// if no key found in encrypted local store - create a key</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_key == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				generateKey<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> _key<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>After you&#8217;ve created the encrypted database you can navigate to the database file and try to open it. The database file will not open in your <a href="http://sqlitebrowser.sourceforge.net" target="_blank" title="SQLite Database Browser">database browser</a> application since the actual database file has been encrypted.</p>
<p><img src="http://www.digitaldogbyte.com/images/sqlite_encryption/sqlite_open_error.png" alt="SQLite open error" border="0" height="417" width="511" /></p>
<p>Here are the download links to the example <a href="http://www.digitaldogbyte.com/downloads/sqlite_encryption/SQLiteEncryption.air" title="SQLite Encryption Sample Application" target="_blank">application</a> &amp; <a href="http://www.digitaldogbyte.com/downloads/sqlite_encryption/SQLiteEncryption.zip" title="SQLite Encryption Sample Application Code" target="_blank">code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2009/02/10/sqlite-encryption-in-air-15/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypting Local Data with Adobe AIR</title>
		<link>http://www.digitaldogbyte.com/2009/01/17/encrypting-local-data-with-adobe-air/</link>
		<comments>http://www.digitaldogbyte.com/2009/01/17/encrypting-local-data-with-adobe-air/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 19:39:51 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=8</guid>
		<description><![CDATA[The Adobe AIR 1.1 runtime provides built-in encryption for the local store. This feature can be used to secure sensitive information like usernames &#38; passwords for web services. The encrypted local store can be found at these locations on a user&#8217;s computer: Windows: C:\Documents and Settings\&#60;username&#62;\Application Data\Adobe\AIR\ELS\ Mac OS: /Users/&#60;username&#62;/Library/Application Support/Adobe/AIR/ELS/ To use the AIR&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>The Adobe AIR 1.1 runtime provides built-in encryption for the local store.</p>
<p>This feature can be used to secure sensitive information like usernames &amp; passwords for web services.</p>
<p>The encrypted local store can be found at these locations on a user&#8217;s computer:</p>
<p>Windows: C:\Documents and Settings\&lt;username&gt;\Application Data\Adobe\AIR\ELS\</p>
<p>Mac OS: /Users/&lt;username&gt;/Library/Application Support/Adobe/AIR/ELS/</p>
<p>To use the AIR&#8217;s encrypted local store you will need to include the following packages:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>EncryptedLocalStore<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ByteArray</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>The following code shows an example of encrypting a string and then storing it in the EncryptedLocalStore object. The strToEncrypt string needs to be converted into a ByteArray since the EncryptedLocalStore stores all of it&#8217;s data as a hash table that uses strings as keys and byte arrays for the data. In our example, we convert the strToEncrypt into a byteArray as the myByteArray variable using the ByteArray object&#8217;s writeUTFBytes method. We are now ready to save our data into the EncryptedLocalStore, which is done by using the EncryptedLocalStore&#8217;s setItem method. The setItem method takes a string parameter that it uses as the key for the hash table and then a byte array as the data that it needs to store.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> strToEncrypt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Herman&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> myByteArray<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
myByteArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span>strToEncrypt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
EncryptedLocalStore<span style="color: #000066; font-weight: bold;">.</span>setItem<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;firstName&quot;</span><span style="color: #000066; font-weight: bold;">,</span> myByteArray<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>To retrieve the encrypted data from the EncryptedLocaStore you will need to use the getItem method and the string key for the data that you want to retrieve from the hash table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> storedValue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = EncryptedLocalStore<span style="color: #000066; font-weight: bold;">.</span>getItem<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;firstName&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// get the string from the storedValue byte array and store in the strDecrypted variable</span>
<span style="color: #6699cc; font-weight: bold;">var</span> strDecrypted<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = storedValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>storedValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>strDecrypted<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// &quot;Herman&quot;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// read the string from the storedValue byte array</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>storedValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>storedValue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// &quot;Herman&quot;</span></pre></td></tr></table></div>

<p>More documentation can on the EncryptedLocalStore class can be found on <a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7e31.html" target="_blank">Adobe&#8217;s site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2009/01/17/encrypting-local-data-with-adobe-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamically attaching library objects in ActionScript 3.0</title>
		<link>http://www.digitaldogbyte.com/2008/07/02/dynamically-attaching-library-objects-in-actionscript-30/</link>
		<comments>http://www.digitaldogbyte.com/2008/07/02/dynamically-attaching-library-objects-in-actionscript-30/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 21:39:47 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[dynamically attach]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=6</guid>
		<description><![CDATA[There are some small differences in syntax when dynamically attaching library objects in ActionScript 2.0 and ActionScript 3.0. In this post, I will provide a very simplified example in both ActionScript 2.0 and ActionScript 3.0. ActionScript 2.0 Example: You will need to make sure the library object that you are trying to attach has been [...]]]></description>
			<content:encoded><![CDATA[<p>There are some small differences in syntax when dynamically attaching library objects in ActionScript 2.0 and ActionScript 3.0.</p>
<p>In this post, I will provide a very simplified example in both ActionScript 2.0 and ActionScript 3.0.</p>
<p><strong>ActionScript 2.0 Example:</strong></p>
<p>You will need to make sure the library object that you are trying to attach has been configured, to do this you need to right click on the object in the library, next select properties and then check the &#8220;Export for ActionScript&#8221; and &#8220;Export in first frame&#8221; options. Make sure to enter an Identifier name for the library object; the Identifier name is used to reference the library object in when you try to use it in the ActionScript code.</p>
<p>In this example we will use &#8220;myClip&#8221; as the Identifier name.</p>
<p><img src="/images/dynamic_attach/as2_export.jpg" /></p>
<p>Below is the ActionScript 2.0 code that will dynamically create 5 instances of the myClip object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> numberOfClips<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xStart<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> yStart<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xVal<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = xStart<span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xOffset<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>numberofclips<span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span> 
     <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>attachMovie<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>getNextHighestDepth<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
     <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>_y = yStart<span style="color: #000066; font-weight: bold;">;</span> 
     <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>_x = xVal<span style="color: #000066; font-weight: bold;">;</span> 
     xVal = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>_x <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>_width <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>xOffset<span style="color: #000066; font-weight: bold;">;</span> 
     <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = i<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>ActionScript 3.0 Example:</strong></p>
<p>You will need to make sure the library object that you are trying to attach has been configured, to do this you need to right click on the object in the library, next select properties and then check the &#8220;Export for ActionScript&#8221; and &#8220;Export in first frame&#8221; options. Make sure to enter an Class name for the library object; the Class name is used to reference the library object in when you try to use it in the ActionScript code. You don&#8217;t need to worry about the Base class, Flash will set a default Base class.</p>
<p><em>If you are attempting to attach a custom class that you created, you will need to use the Class name of the your custom class; you may also need to set the Base class if your custom class is derived from another custom class that you have created. </em></p>
<p><img src="/images/dynamic_attach/as3_export.jpg" /></p>
<p>When you check the &#8220;Export for ActionScript&#8221; option, you will likely get a warning telling you that there is no class file found; for this basic example you can just click OK.</p>
<p><img src="/images/dynamic_attach/as3_export_class_warning.jpg" /></p>
<p>Below is the ActionScript 3.0 code that will dynamically create 5 instances of the myClip object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> numberOfClips<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xStart<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> yStart<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xVal<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = xStart<span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #6699cc; font-weight: bold;">var</span> xOffset<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>numberofclips<span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span> 
     <span style="color: #6699cc; font-weight: bold;">var</span> mc<span style="color: #000066; font-weight: bold;">:</span>myClip = <span style="color: #0033ff; font-weight: bold;">new</span> myClip<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
     mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;myClip&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
     <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span> <span style="color: #000000;">&#40;</span>mc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
     mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = yStart<span style="color: #000066; font-weight: bold;">;</span> 
     mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = xVal<span style="color: #000066; font-weight: bold;">;</span> 
     xVal = mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>xOffset<span style="color: #000066; font-weight: bold;">;</span> 
     mc<span style="color: #000066; font-weight: bold;">.</span>label_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Here are the <a href="/downloads/dynamic_attach_example.zip">example source files</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2008/07/02/dynamically-attaching-library-objects-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UML &amp; ActionScript 3.0 Code Generation</title>
		<link>http://www.digitaldogbyte.com/2008/02/18/uml-actionscript-30-code-generation/</link>
		<comments>http://www.digitaldogbyte.com/2008/02/18/uml-actionscript-30-code-generation/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 03:34:01 +0000</pubDate>
		<dc:creator>Herm Wong</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[code generation]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://www.digitaldogbyte.com/?p=3</guid>
		<description><![CDATA[I&#8217;m currently architecting an ActionScript 3.0 Framework that will take advantage of OOP principles &#38; a MVC design pattern. In an attempt to automate as much of the work as possible, I started looking for tools that could generate AS3.0 code from UML diagrams. I found an excellent blog post by Sean Moore, with a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently architecting an ActionScript 3.0 Framework that will take advantage of OOP principles &amp; a MVC design pattern.</p>
<p>In an attempt to automate as much of the work as possible, I started looking for tools that could generate AS3.0 code from UML diagrams. I found an excellent <a href="http://seantheflashguy.com/blog/2007/11/20/actionscript-30-uml-and-code-generation-tools/" target="_blank" title="ActionScript 3.0 UML and Code Generation Tools">blog post</a> by Sean Moore, with a listing of several UML diagramming tools with AS3.0 code generation.</p>
<p>I decided to use <a href="http://staruml.sourceforge.net/en/download.php" target="_blank" title="Download StarUML">StarUML</a>, which was mentioned in one of the comments. To enable AS3.0 code generation in StarUML, you will need to <a href="http://www.flashfocus.nl/forum/showthread.php?t=37074" title="Download AS3.zip">download the AS3.zip</a> file &amp; then copy the contents of the AS3.zip file to this directory location C:\Program Files\StarUML\modules\staruml-generator\templates\.</p>
<p>The template.cot file is a JavaScript file that StarUML uses to generate the AS3.0 code. I noticed that the AS3.0 code being generated did not include the package namespace of the parent class or the implemented interfaces, so I modified the template.cot file so that it generates the import statements of the missing namespaces. My colleague also made some revisions to the template.cot file so that it would not include the access control modifiers for the operations created in the interface AS files.</p>
<p>To install the modified template.cot file you can simply overwrite the C:\Program Files\StarUML\modules\staruml-generator\templates\AS3 folder with the contents of this <a href="http://www.digitaldogbyte.com/downloads/AS3.zip" title="Modified AS3.zip">AS3.zip</a> file.</p>
<p>Here are the steps that you&#8217;ll need to follow to generate the AS3.0 code once you have the AS3.zip contents installed.</p>
<p>1. When you start StarUML, it will ask you for the approach you wish to use. Leave it as Default Approach and press OK.</p>
<p><img src="/images/staruml_as3/staruml_as3_01.jpg" /></p>
<p>2. Once you have created your UML diagrams and want to generate the AS3.0 code, go to the Tools menu and select &#8220;StartUML Generator &#8230;&#8221;.</p>
<p><img src="/images/staruml_as3/staruml_as3_02.jpg" /></p>
<p>3. You will be presented with a dialog asking for the template type that StarUML should use for code generation; check the AS3.0 template and click Next.</p>
<p><img src="/images/staruml_as3/staruml_as3_03.jpg" /></p>
<p>4. Select the destination directory that StarUML will place the generated AS3.0 code and then press Next.</p>
<p><img src="/images/staruml_as3/staruml_as3_04.jpg" /></p>
<p>5. Press the Generate button to begin the code generation.</p>
<p><img src="/images/staruml_as3/staruml_as3_05.jpg" /></p>
<p>6. Presto! Code generation complete. Click on Finish and then go to the destination folder that you specified in Step 4 to view your results.</p>
<p><img src="/images/staruml_as3/staruml_as3_06.jpg" /></p>
<p>Here is a <a href="/downloads/staruml_as3_example.zip" title="StarUML Sample Files">sample project</a> that I created that you can use as a starting reference point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitaldogbyte.com/2008/02/18/uml-actionscript-30-code-generation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

