<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Dan Schultz, Intrigue Media</title>
	<atom:link href="http://www.intriguemedia.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intriguemedia.net</link>
	<description>All things Flex, AIR, Application Architecture and Cayri from Dan Schultz</description>
	<pubDate>Fri, 01 Aug 2008 23:54:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Saving Flex&#8217;s Application State to a Database</title>
		<link>http://www.intriguemedia.net/2008/03/10/saving-flexs-application-state-to-a-database/</link>
		<comments>http://www.intriguemedia.net/2008/03/10/saving-flexs-application-state-to-a-database/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 20:08:59 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Design Patterns]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/2008/03/10/saving-flexs-application-state-to-a-database/</guid>
		<description><![CDATA[Bill Sanders has a great post on the Memento design pattern over at his blog.  After reading it, I thought I&#8217;d chime in and post a technique that takes the memento one step further.  This approach allows you to serialize a Memento object into a ByteArray and save it into a database.  [...]]]></description>
			<content:encoded><![CDATA[<p>Bill Sanders has a great <a href="http://www.as3dp.com/2008/01/24/actionscript-30-memento-design-pattern-encapsulating-saved-states/" target="_blank">post</a> on the Memento design pattern over at his blog.  After reading it, I thought I&#8217;d chime in and post a technique that takes the memento one step further.  This approach allows you to serialize a Memento object into a ByteArray and save it into a database.  Then, retrieving the Memento object from the server, dynamically instantiated it, and restoring its previous state.</p>
<p>One major draw back to the Memento, as you&#8217;ll see, is that restoring an object&#8217;s state can be a very expensive operation.  Especially in a Flex environment where restoring a Memento could trigger a large display list invalidation.  For that reason, the Memento is not always the ideal pattern for implementing undo/redo functionality.  The alternative pattern for implementing this functionality is the Command pattern.  With the Command pattern, each command is only concerned about a particular action to get to the current state of the application.  With this, you can have an <em>undo()</em> method in each of your commands that undoes whatever action was performed in your <em>execute()</em> method.</p>
<p>Ok, so where could we apply the Memento then?  Hmm .. how about a Monopoly game!  Since a game of Monopoly can be pretty lengthy, the user might want to be able to save the game on the server, so that he/she can come back later to finish it off.  There&#8217;s a couple ways to accomplish this functionality:</p>
<ul>
<li>Create a multitude of database tables that represent objects in your application.  For example, a Player&#8217;s table to keep track of the current players, how much money they have, etc.  A Properties table to keep track of the game&#8217;s properties.  A Properties to Players linking table to store which properties each player owns, and so on.</li>
<li>OR, create one table whose role is to store Mementos for each of the objects in the game.  I think this approach sounds easier, and since it&#8217;s in the scope of this article, we&#8217;re going to focus on this approach.</li>
</ul>
<p><strong>The Memento Classes</strong><br />
<img src='http://www.intriguemedia.net/wp-content/uploads/2008/03/memento.jpg' alt='Memento UML' /><br />
In order for our application to save its state using the Memento pattern, we need to write a couple classes and interfaces that our objects will implement.  Note that my Memento classes slightly differ from that described on <a href="http://en.wikipedia.org/wiki/Memento_pattern" target="_blank">Wikipedia</a> and <a href="http://www.as3dp.com/2008/01/24/actionscript-30-memento-design-pattern-encapsulating-saved-states/" target="_blank">Bill Sanders blog</a>.  The reason for this was that I wanted to inspect which type of object each Memento originated from.  By doing this, you can re-instantiate the Memento dynamically when it comes back from the database.  I also wanted any classes that supported restoration to be of a certain type â€“ <em>IRestorable</em>.</p>
<p>Each class that you want to save and restore state to must implement the <em>IRestorable</em> interface.  This interface has two simple methods that either creates or accepts a Memento object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> IRestorable
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> restore<span style="color: #66cc66;">&#40;</span>state:ObjectState<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
    <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ObjectState;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Next is the Memento class that is called <em>ObjectState</em>.  This class is where you store all the data that the class needs to restore its state back to what it was.  These objects can also be serialized and saved to the database (<a href="#saving">more on this later</a>).  You&#8217;ll notice that I&#8217;ve marked this class as dynamic so that you can add anything you want to it.  The only defined property it has is <em>className</em>.  You set this to the fully qualified class name that generated the Memento.  Another important thing to note: you <strong>must</strong> put the [RemoteClass] metatag in the <em>ObjectState</em> class definition.  I&#8217;ll <a href="#retrieving">show you later</a> how you can use this property to re-instantiate the object based on this class name property.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="actionscript"><span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;my.custom.package.ObjectState&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">dynamic</span> <span style="color: #000000; font-weight: bold;">class</span> ObjectState
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> className:<span style="color: #0066CC;">String</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Pretty simple stuff, huh?  Let&#8217;s take a look at a simple class that implements both of these classes.  This class, called <em>MyCustomComp</em>, implements the IRestorable interface with the two methods described above.  The <em>save()</em> method&#8217;s job is to take all the data that this component needs to re-instantiate itself and save it to a new ObjectState.  In our case, it&#8217;s the text strings from the three TextInput controls.  The <em>restore()</em> method&#8217;s job is to take those three text strings, and reapply them to our TextInput controls.  So whatever is done in the <em>restore()</em> method, needs to be saved to the ObjectState in the <em>save()</em> method.</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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code"><pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyCustomComp <span style="color: #0066CC;">extends</span> UIComponent <span style="color: #0066CC;">implements</span> IRestorable
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// Sub-components in our component that we want to </span>
    <span style="color: #808080; font-style: italic;">// restore the data to.</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> textInput1:TextInput;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> textInput2:TextInput;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> textInput3:TextInput;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyCustomComp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    override protected <span style="color: #000000; font-weight: bold;">function</span> createChildren<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span>.<span style="color: #006600;">createChildren</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Create the sub-components.</span>
        textInput1 = <span style="color: #000000; font-weight: bold;">new</span> TextInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        textInput1.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Text 1&quot;</span>;
        addChild<span style="color: #66cc66;">&#40;</span>textInput1<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        textInput2 = <span style="color: #000000; font-weight: bold;">new</span> TextInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        textInput2.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Text 2&quot;</span>;
        addChild<span style="color: #66cc66;">&#40;</span>textInput2<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        textInput3 = <span style="color: #000000; font-weight: bold;">new</span> TextInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        textInput3.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Text 3&quot;</span>;
        addChild<span style="color: #66cc66;">&#40;</span>textInput3<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> restore<span style="color: #66cc66;">&#40;</span>state:ObjectState<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// Make sure to throw a TypeError if the class name is </span>
        <span style="color: #808080; font-style: italic;">// incorrect.</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>state.<span style="color: #006600;">className</span> <span style="color: #66cc66;">!</span>= flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">getQualifiedClassName</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> TypeError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This ObjectState was not created from the MyCustomComp class&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Take the text data from the ObjectState and restore </span>
        <span style="color: #808080; font-style: italic;">// it to our sub-components.</span>
        textInput1.<span style="color: #0066CC;">text</span> = state.<span style="color: #006600;">text1</span>;
        textInput2.<span style="color: #0066CC;">text</span> = state.<span style="color: #006600;">text2</span>;
        textInput3.<span style="color: #0066CC;">text</span> = state.<span style="color: #006600;">text3</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Restore the position of the component.</span>
        x = state.<span style="color: #006600;">xPos</span>;
        y = state.<span style="color: #006600;">yPos</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ObjectState
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> state:ObjectState = <span style="color: #000000; font-weight: bold;">new</span> ObjectState<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        state.<span style="color: #006600;">className</span> = flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">getQualifiedClassName</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Since the ObjectState is dynamic, we can set anything</span>
        <span style="color: #808080; font-style: italic;">// on it.  Set the text from each of the sub-components </span>
        <span style="color: #808080; font-style: italic;">// into our memento object.</span>
        state.<span style="color: #006600;">text1</span> = textInput1.<span style="color: #0066CC;">text</span>;
        state.<span style="color: #006600;">text2</span> = textInput2.<span style="color: #0066CC;">text</span>;
        state.<span style="color: #006600;">text3</span> = textInput3.<span style="color: #0066CC;">text</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Save the X and Y positioning of this component.</span>
        state.<span style="color: #006600;">xPos</span> = x;
        state.<span style="color: #006600;">yPos</span> = y;
&nbsp;
        <span style="color: #b1b100;">return</span> state;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><a name="saving"></a><strong>Serializing the ObjectState to the Database</strong><br />
When it&#8217;s time to send the ObjectState across the wire and save it to the database, we need to do a simple operation first.  This operation will save the ObjectState into a ByteArray so that the database can store it.</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="actionscript"><span style="color: #808080; font-style: italic;">// The component that we want to save and restore data to.</span>
<span style="color: #000000; font-weight: bold;">var</span> myRestorableComp:MyCustomComp = <span style="color: #000000; font-weight: bold;">new</span> MyCustomComp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
<span style="color: #808080; font-style: italic;">// Save the component's state.</span>
<span style="color: #000000; font-weight: bold;">var</span> state:ObjectState = myRestorableComp.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Write the state object into a ByteArray.</span>
<span style="color: #000000; font-weight: bold;">var</span> stateBytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
bytes.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>state<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Code to send the ByteArray to the server via Flash Remoting.</span>
myService:RemoteObject = myRemotingService;
myService.<span style="color: #006600;">saveMemento</span><span style="color: #66cc66;">&#40;</span>stateBytes<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Also, in order to save serialized objects to a database, you need to set the field in which they&#8217;re stored as a BLOB.  This way, the serialized structure of the object isn&#8217;t modified when you save it.</p>
<p><a name="retrieving"></a><strong>Retrieving the Memento from the Server</strong><br />
After we save the state to the database, a user will more than likely want to retrieve it.  Also, you might want to dynamically re-instantiate the component that the Memento&#8217;s originated from.  You can achieve this by passing the ObjectState&#8217;s <em>className</em> property into Flash&#8217;s <em>flash.utils.getDefinitionByName()</em> method.</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
</pre></td><td class="code"><pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyCompContainer <span style="color: #0066CC;">extends</span> Canvas
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> service:RemoteObject;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyCompContainer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        service = <span style="color: #000000; font-weight: bold;">new</span> RemoteObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        service.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>, retrievedMementoHandler<span style="color: #66cc66;">&#41;</span>;
        ...
        <span style="color: #006600;">service</span>.<span style="color: #006600;">retrieveMemento</span><span style="color: #66cc66;">&#40;</span>someUniqueMementoId<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// The result handler that was added to the remoting object.</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> retrievedMementoHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// We saved the ObjectState into a ByteArray, so we're </span>
        <span style="color: #808080; font-style: italic;">// going to get it back as a ByteArray.</span>
        <span style="color: #000000; font-weight: bold;">var</span> stateBytes:ByteArray = event.<span style="color: #006600;">result</span> as ByteArray;
        stateBytes.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// Read the Memento from the ByteArray.</span>
        <span style="color: #000000; font-weight: bold;">var</span> compState:ObjectState = stateBytes.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ObjectState;
&nbsp;
        <span style="color: #808080; font-style: italic;">// We can inspect the type that the ObjectState </span>
        <span style="color: #808080; font-style: italic;">// originated from.</span>
        <span style="color: #000000; font-weight: bold;">var</span> restorableComp:IRestorable = flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">getDefinitionByName</span><span style="color: #66cc66;">&#40;</span>compState.<span style="color: #006600;">className</span><span style="color: #66cc66;">&#41;</span>;
        restorableComp.<span style="color: #006600;">restore</span><span style="color: #66cc66;">&#40;</span>compState<span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">// If this is a UIComponent, let's add it to the stage.</span>
        <span style="color: #808080; font-style: italic;">// Since we saved the x and y positioning in the </span>
        <span style="color: #808080; font-style: italic;">// ObjectState, it will position itself to where it was </span>
        <span style="color: #808080; font-style: italic;">// when it was saved.</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>restorableComp is UIComponent<span style="color: #66cc66;">&#41;</span>
            addChild<span style="color: #66cc66;">&#40;</span>restorableComp as UIComponent<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>By using the Memento pattern, we&#8217;ve encapsulate the implementation of storing and retrieving an object&#8217;s state.  We&#8217;ve also made it generic enough, that we can serialize the object&#8217;s state and store it into a database table.  Once in the database table, the state can be retrieved and instantiated later.</p>
<p><strong>Pitfalls of this Approach</strong><br />
Like any design pattern out there, this approach has its draw backs.  One consequence of this technique is the difficulty to change the data inside your Mementos.  The reason for this is the way that we use serialization.  Since the objects are serialized in the database, you can&#8217;t easily add additional data to the ObjectStates.  However, there are workarounds for this.  You can save a version number along with your ObjectState.  This version number can be used in conjunction with a separate class that deals with reading each ObjectState&#8217;s data.  When the class inspects the version number, it can change its parsing logic to deal with different versions of the ObjectState.</p>
<p>Another drawback is the inability to do a database query on the data inside your ObjectStates.  Again, since the objects are serialized, there&#8217;s no easy way to do this.  You can, however, work around this though by storing the query data in either a separate table, or along side the ObjectState when it&#8217;s saved.</p>
<p>Hopefully this technique is something you can add to your toolkit.  It definitely has its share of drawbacks, but if you&#8217;re looking for an easy way to save the state of your application, this is certainly a pretty trivial and elegant way of accomplishing it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2008/03/10/saving-flexs-application-state-to-a-database/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Loading Modules/Runtime CSS into an AIR App</title>
		<link>http://www.intriguemedia.net/2008/02/22/loading-modulesruntime-css-into-an-air-app/</link>
		<comments>http://www.intriguemedia.net/2008/02/22/loading-modulesruntime-css-into-an-air-app/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 05:04:55 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.intriguemedia.net/2008/02/22/loading-modulesruntime-css-into-an-air-app/</guid>
		<description><![CDATA[For those planning to load a Flex module into your AIR application from a remote server: take a look at this post before beating your head against the wall with this ambiguous error message Error: Unable to load style(SWF is not a loadable module).
Basically, loaded SWF&#8217;s are not allowed to be in the same security [...]]]></description>
			<content:encoded><![CDATA[<p>For those planning to load a Flex module into your AIR application from a remote server: take a look at <a href="http://tech.groups.yahoo.com/group/apollocoders/message/2124" target="_blank">this post</a> before beating your head against the wall with this ambiguous error message <code>Error: Unable to load style(SWF is not a loadable module)</code>.</p>
<p>Basically, loaded SWF&#8217;s are not allowed to be in the same security domain as your AIR app.  Since modules and external styles loaded using <code>StyleManager.loadStyleDeclaration()</code> try to load themselves into the current security domain, an error will be thrown.  The only workaround it appears is to bundle those modules with your application when it&#8217;s downloaded.  Any new modules you want to add to you app at a later time can be downloaded using AIR&#8217;s update API via <code>Updater.update()</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2008/02/22/loading-modulesruntime-css-into-an-air-app/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MVC meet H-MVC â€“ Hierarchical MVC</title>
		<link>http://www.intriguemedia.net/2008/02/07/mvc-meet-h-mvc-%e2%80%93-hierarchical-mvc/</link>
		<comments>http://www.intriguemedia.net/2008/02/07/mvc-meet-h-mvc-%e2%80%93-hierarchical-mvc/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 19:52:13 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Design Patterns]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/2008/02/07/mvc-meet-h-mvc-%e2%80%93-hierarchical-mvc/</guid>
		<description><![CDATA[Lately I&#8217;ve been experimenting and researching with a lot of various UI architectures that either derive from model-view-controller, or depart from it completely.
After using Cairngorm for a dozen or so projects, you begin to ask yourself, &#8220;Is there something out there better than this?&#8221;  I literally felt like Cairngorm turned me into a robot [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been experimenting and researching with a lot of various UI architectures that either derive from model-view-controller, or depart from it completely.</p>
<p>After using <a href="http://labs.adobe.com/wiki/index.php/Cairngorm" target="_blank">Cairngorm</a> for a dozen or so projects, you begin to ask yourself, &#8220;Is there something out there better than this?&#8221;  I literally felt like Cairngorm turned me into a robot â€“ create event, create event type, create command, add to front controller &#8230; create event, create event type, create command, add to front controller &#8230; wash, rinse, repeat.  This mundane process finally put me on a quest for a better solution.</p>
<p>Some argue that Cairngorm is best suited for enterprise level applications where you have multiple people all working on the same project, and sharing the same files.  From my experiences, I would disagree.  You wouldn&#8217;t believe how many duplicate events and commands we had splashed around our applications.  I think this is attributed to Cairngorm&#8217;s lack of defining a uniformed structure of an application.  Oh yea, and lets not even start on the subject of where you have the multiple instances of a view being tied to a single model.</p>
<p>In my search for a better MVC solution, I had a few guidelines that the pattern should meet:</p>
<ol>
<li>Separating pieces of an application into their own modules or &#8220;sections.&#8221;  By doing this, it makes it easier to replace UI interaction, or add feature XYZ when your boss comes knocking on your door.</li>
<li>Reduce dependencies between each &#8220;section&#8221; of an application.  I know, I&#8217;m asking a lot here; however, just because a component in a panel on the left side of your app communicates with another panel on the right side of your app, doesn&#8217;t mean they need to have direct dependencies between them.</li>
<li>Reduce dependencies between the model and the view.  In traditional MVC and Cairngorm, the view is allowed to be coupled to the model, and the model indirectly tied to the view via the Observer pattern (i.e. data binding).  By untying the view from the model, you now make your views more robust by being able to use it with an albeit similar, but different model.</li>
<li>Being able to work with the Flex module loading framework.  Cairngorm has some <a href="http://viconflex.blogspot.com/2007/05/can-cairngorm-and-modules-play-nice.html" target="_blank">issues</a> related to this, and there are some <a href="http://viconflex.blogspot.com/2007/05/loading-multiple-independent-instances.html" target="_blank">workarounds</a> for it, but generally speaking, Cairngorm wasn&#8217;t designed with module loading in mind.</li>
<li><em>Completely</em> free of singletons.  Singletons have their time and place, but a <strong>model should never be a singleton!</strong>  This is like putting your data in concrete.  Just because you think <em>now</em> that you&#8217;re never going to need multiple instances of an object, doesn&#8217;t mean that you won&#8217;t have to in the future.  On top of that, singletons are nearly impossible to subclass.  At the very least, have your singleton classes conform to an interface.  This way you can change its implementation in the future.  Ok, I&#8217;m getting off topic ..</li>
</ol>
<p><strong>MVC meet H-MVC â€“ Hierarchical MVC</strong><br />
From my research, H-MVC is a pattern used mostly in the Java world, and is unknowingly based off of the <a href="http://en.wikipedia.org/wiki/Presentation-abstraction-control" target="_blank">PAC</a> (Presentation-Abstraction-Control) pattern.  H-MVC answers the following questions when architecting a UI:</p>
<ul>
<li>What&#8217;s a consistent way of structuring my UI code?</li>
<li>What&#8217;s a good way to cleanly separate my views from my domain model, and make them reusable?</li>
<li>What&#8217;s a good pattern to easily allow for application flow, and inter-component communication?</li>
</ul>
<p>At its core H-MVC is an event based framework that makes a clean break between your models and your views.  On top of this separation, it effectively allows your views and models to communicate with other parts of your application by simply firing events.  This communication works by controllers propagating these events throughout the whole application.  Think event bubbling in Flash, but instead of this happening through the views, it happens through the controllers.</p>
<p align="center">
<img src='http://www.intriguemedia.net/wp-content/uploads/2008/02/jw-0721-hmvc1.gif' alt='H-MVC Diagram'/><br />
Image taken from the <a href="http://www.javaworld.com/javaworld/jw-07-2000/jw-0721-hmvc.html?page=1" target="_blank">JavaWorld HMVC</a> article.
</p>
<p>Let&#8217;s take the example where Component A is its own view that contains a single button.  We have another view called Component B that contains a ViewStack.  On top of that, Component B is nested somewhere in our application that is completely outside the visibility of A.  When the button is clicked in A, we want B to switch the selectedIndex of its ViewStack to 2.  H-MVC successfully decouples the communication by making the assumption that a parent will always know about its children, but the children never knows about its parent.</p>
<p>Since this post is getting pretty long, I&#8217;ll hold off showing any code examples till my next post.  In the mean time, if you want to do a little reading on H-MVC, check out the original <a href="http://www.javaworld.com/javaworld/jw-07-2000/jw-0721-hmvc.html?page=1" target="_blank">article</a> written by Jason Cai, Ranjit Kapila and Gaurav Pal.  There&#8217;s also another article that&#8217;s dramatically shorter and gives a good <a href="http://www.thecentric.com/wiki/index.php/HMVC_Tutorial" target="_blank">overview</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2008/02/07/mvc-meet-h-mvc-%e2%80%93-hierarchical-mvc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CollectionEventKind.RESET, WTF Does That Mean?</title>
		<link>http://www.intriguemedia.net/2007/10/06/collectioneventkindreset-wtf-does-that-mean/</link>
		<comments>http://www.intriguemedia.net/2007/10/06/collectioneventkindreset-wtf-does-that-mean/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 00:39:43 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=29</guid>
		<description><![CDATA[When handling Flex&#8217;s collection change events, most of the change types are pretty self-explanatory.  For example, CollectionEventKind.ADD is when an item is added to the collection, or CollectionEventKind.UPDATE is when an item&#8217;s property inside the collection changes.  However, there&#8217;s this ambiguous change type called RESET.  The documentation does a wonderful job of [...]]]></description>
			<content:encoded><![CDATA[<p>When handling Flex&#8217;s collection change events, most of the change types are pretty self-explanatory.  For example, <code>CollectionEventKind.ADD</code> is when an item is added to the collection, or <code>CollectionEventKind.UPDATE</code> is when an item&#8217;s property inside the collection changes.  However, there&#8217;s this ambiguous change type called RESET.  The documentation does a wonderful job of describing when this type of collection event is fired: <em>Indicates that the collection has changed so <strong>drastically</strong> that a reset is required.</em> (<a href="http://livedocs.adobe.com/flex/201/langref/mx/events/CollectionEventKind.html#RESET" title="CollectionEventKind" target="_blank">ASDoc Link</a>)</p>
<p>Digging through ListCollectionView provides some better insight of when RESET is dispatched.  Anytime a collection is passed to <code>ListCollectionView.list</code>, and both the old list and the new list has items in it, it will fire a reset collection change event.  Here&#8217;s the code Adobe uses for setting a list on ListCollectionView:</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="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">list</span><span style="color: #66cc66;">&#40;</span>value:IList<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_list <span style="color: #66cc66;">!</span>= value<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> oldHasItems:<span style="color: #0066CC;">Boolean</span>;
            <span style="color: #000000; font-weight: bold;">var</span> newHasItems:<span style="color: #0066CC;">Boolean</span>;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_list<span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                _list.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>CollectionEvent.<span style="color: #006600;">COLLECTION_CHANGE</span>,
                                          listChangeHandler<span style="color: #66cc66;">&#41;</span>;
                oldHasItems = _list.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            _list = value;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_list<span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #808080; font-style: italic;">// weak listeners to collections and dataproviders</span>
                _list.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>CollectionEvent.<span style="color: #006600;">COLLECTION_CHANGE</span>,
                                       listChangeHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
                newHasItems = _list.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>oldHasItems <span style="color: #66cc66;">||</span> newHasItems<span style="color: #66cc66;">&#41;</span>
                reset<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;listChanged&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Lastly, ListCollectionView is a pretty useful class.  A lot of new Flex developers go straight to using ArrayCollection, and forget about its father, ListCollectionView.  This collection allows you to apply different sorts and filters on a collection without directly modifying the wrapped collection.  You can also call <code>addItem()</code> and <code>removeItemAt()</code> on ListCollectionView and have it modify the wrapped collection.  Pretty nifty! Here&#8217;s an example of it in action:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> col:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
col.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span>;
col.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'b'</span><span style="color: #66cc66;">&#41;</span>;
col.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'c'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> wrapper:ListCollectionView = <span style="color: #000000; font-weight: bold;">new</span> ListCollectionView<span style="color: #66cc66;">&#40;</span>col<span style="color: #66cc66;">&#41;</span>;
wrapper.<span style="color: #006600;">removeItemAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
wrapper.<span style="color: #006600;">removeItemAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
wrapper.<span style="color: #006600;">removeItemAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>col.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// traces: 0</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/10/06/collectioneventkindreset-wtf-does-that-mean/feed/</wfw:commentRss>
		</item>
		<item>
		<title>When to Use Weak References</title>
		<link>http://www.intriguemedia.net/2007/09/24/when-to-use-weak-references/</link>
		<comments>http://www.intriguemedia.net/2007/09/24/when-to-use-weak-references/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 22:34:40 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[Design Patterns]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=28</guid>
		<description><![CDATA[Understanding when to use a weak references, versus strong references can be a confusing one.  It took me awhile to fully grasp when, and when not to use one over the other.  On top of that, there&#8217;s very little documentation on the LiveDocs about the subject.  Under the documentation for IEventDispatcher.addEventListener(), it [...]]]></description>
			<content:encoded><![CDATA[<p>Understanding when to use a weak references, versus strong references can be a confusing one.  It took me awhile to fully grasp when, and when not to use one over the other.  On top of that, there&#8217;s very little documentation on the LiveDocs about the subject.  Under the documentation for <code>IEventDispatcher.addEventListener()</code>, it states:</p>
<blockquote><p><em>useWeakReference:Boolean (default = false) â€” Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.</em></p></blockquote>
<p>And here&#8217;s what they have listed for the Dictionary&#8217;s constructor:</p>
<blockquote><p><em>weakKeys:Boolean (default = false) â€” Instructs the Dictionary object to use &#8220;weak&#8221; references on object keys. If the only reference to an object is in the specified Dictionary object, the key is eligible for garbage collection and is removed from the table when the object is collected.</em></p></blockquote>
<p><em>Ok &#8230; thanks.</em>  So, I did some Googling, <strike>and both <a href="http://www.onflex.org/ted/2006/09/max-actionscript-3-performance-tuning.php" title=" MAX - ActionScript 3 Performance Tuning - Strong Typing" target="_blank">Ted Patrick</a></strike> and <a href="http://www.colettas.org/?p=115" title="Flex Tip of the Day: Do you need a weak reference in your event listener?" target="_blank">David Coletta</a> have much better information on the subject.</p>
<p>The basic idea behind strong references and <code>addEventListener</code> is this: when you call <code>addEventListener</code> and you pass it the function that you want to be called when the event fires, the event dispatcher is actually grabbing and holding a reference to that class and function it contains.  As we all know, an object won&#8217;t be garbage collected until every reference to it doesn&#8217;t exist anymore.  This insures that the event dispatcher always has a reference to the function that needs to be called.  However, if you&#8217;re not careful, this can be a breading ground for nasty memory leaks.</p>
<p>So, here&#8217;s my short list of do&#8217;s and don&#8217;ts related to strong vs weak references and event listeners:</p>
<ul>
<li>Always use a weak reference when adding an event listener to a class that&#8217;s a singleton, or any object that you expect to live throughout the life of your application.  Remember, this applies to most of Flex&#8217;s manager classes, including the SystemManager, and any event dispatching classes that your singleton&#8217;s contain.</li>
<li>Always use weak references when adding Cairngorm commands.  The event dispatcher in Cairngorm is a singleton, and will always keep references to those command classes.</li>
<li><strike>According to Ted, weak references are 10x slower.</strike> (True when referring to member access, but not event listening.)</li>
<li>It&#8217;s safe to use strong references when you&#8217;re adding an event listener to itself (i.e. the instance dispatching the event).</li>
<li>You should use a weak reference when adding an event listener to the Timer class.</li>
<li>Lastly, always make sure to clean up and remove any event listeners your classes are using when they&#8217;re no longer needed.  I follow .NET&#8217;s approach, and I have an interface called IDisposable.  This interface contains a single method called <code>dispose()</code>, and inside I remove any event listeners that the class might be using.  Additionally, you could clean-up any BitmapData objects you might be using, among other things.  Most, if not all, of my classes that I write implement this interface, and I just make sure to call <code>dispose()</code> when I know the object is no longer needed.</li>
</ul>
<p>If there&#8217;s anything else to look out for, I&#8217;d love to hear them.  It&#8217;s always good to be proactive when it comes to memory leaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/09/24/when-to-use-weak-references/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Embedding Cayri on Your Website</title>
		<link>http://www.intriguemedia.net/2007/09/12/embedding-cayri-on-your-website/</link>
		<comments>http://www.intriguemedia.net/2007/09/12/embedding-cayri-on-your-website/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 22:48:59 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[Cayri]]></category>

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=27</guid>
		<description><![CDATA[Lately I&#8217;ve been getting emails from people asking me if they can embed Cayri on their virtual airline&#8217;s website.   So I think it&#8217;s about time to post a small tutorial on how to do this.   The simplest way to do it is by using an IFRAME tag with HTML.  Just [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been getting emails from people asking me if they can embed <a href="http://www.cayri.org">Cayri</a> on their virtual airline&#8217;s website.   So I think it&#8217;s about time to post a small tutorial on how to do this.   The simplest way to do it is by using an <a href="http://www.w3schools.com/tags/tag_iframe.asp" target="_blank">IFRAME</a> tag with HTML.  Just stick the following code in any HTML page, and Cayri will show up on your website:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iframe</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.cayri.org/?network=vatsim&quot;</span> <span style="color: #000066;">frameborder</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;700&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iframe&gt;</span></span></pre></td></tr></table></div>

<p>If you would like to show IVAO traffic instead of VATSIM traffic, you&#8217;ll need to replace <strong>?network=vatsim</strong> with <strong>?network=ivao</strong> in the <strong>src</strong> attribute.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/09/12/embedding-cayri-on-your-website/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The State Pattern in Flex 2</title>
		<link>http://www.intriguemedia.net/2007/08/31/the-state-pattern-in-flex-2/</link>
		<comments>http://www.intriguemedia.net/2007/08/31/the-state-pattern-in-flex-2/#comments</comments>
		<pubDate>Sat, 01 Sep 2007 04:36:16 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[Design Patterns]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=26</guid>
		<description><![CDATA[I&#8217;m currently working on Flex project at Quality Attributes Software that requires the use of a set of tools, similar to Photoshop, to manipulate a drawing canvas.  Some examples of tools might be a drag tool, a selection tool, and a zoom tool.  I thought to myself, &#8220;Ok, simple enough.  Throw all [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.intriguemedia.net/2007/08/31/the-state-pattern-in-flex-2/photoshop-tools-thumb/" rel="attachment wp-att-36" title="Photoshop Tools Thumb"><img src="http://www.intriguemedia.net/wp-content/uploads/2007/08/photoshop_tools.jpg" title="Photoshop Tools Thumb" alt="Photoshop Tools Thumb" align="right" /></a>I&#8217;m currently working on Flex project at <a href="http://www.qualityattributes.com" target="_blank">Quality Attributes Software</a> that requires the use of a set of tools, similar to Photoshop, to manipulate a drawing canvas.  Some examples of tools might be a drag tool, a selection tool, and a zoom tool.  I thought to myself, &#8220;<em>Ok, simple enough.  Throw all the logic into a switch statement inside a generic on click button handler.</em>&#8221;  So, when a user clicks on a new tool, disable all the functionality from the previous tool, and enable the functionality of the new one.  Ugh!  This was a complete disaster.  What happens when you expose all this logic, is that you run into some very <em>highly </em>coupled code.  Meaning that each tool is essentially keeping the state of the other tools.  Yuck!</p>
<p>There&#8217;s definitely a better way to handle these situations, and that&#8217;s by using the <strong>state pattern</strong>.  Essentially, I turned each tool into a state.  So when a user clicks on the Selection Tool, the program changes its state to use the functionality of selecting objects on the drawing canvas.  I hide all this logic behind an interface, and each tool is represented as a class that implements this interface.  If you&#8217;d like some code examples of this pattern, William Sanders has a great write up over at <a href="http://www.adobe.com/devnet/flashmediaserver/articles/video_state_machine_as3_03.html" target="_blank">Adobe&#8217;s Developer Center</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/08/31/the-state-pattern-in-flex-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Aircraft Heading Information for IVAO</title>
		<link>http://www.intriguemedia.net/2007/07/25/aircraft-heading-information-for-ivao/</link>
		<comments>http://www.intriguemedia.net/2007/07/25/aircraft-heading-information-for-ivao/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 06:45:06 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[Cayri]]></category>

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=24</guid>
		<description><![CDATA[The heading information for aircraft on the IVAO network has finally been implemented! Thank you for the staff over at IVAO for modifying their server data to supply this information. The difference is truly night and day.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.intriguemedia.net/wp-content/uploads/2007/07/cayri_heading_ivao.jpg" title="cayri_heading_ivao.jpg" alt="cayri_heading_ivao.jpg" align="right" height="112" width="188" />The heading information for aircraft on the IVAO network has finally been implemented! Thank you for the staff over at IVAO for modifying their server data to supply this information. The difference is truly night and day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/07/25/aircraft-heading-information-for-ivao/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cayri on Your Desktop!</title>
		<link>http://www.intriguemedia.net/2007/07/16/cayri-on-your-desktop/</link>
		<comments>http://www.intriguemedia.net/2007/07/16/cayri-on-your-desktop/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 08:09:21 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

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

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=22</guid>
		<description><![CDATA[I&#8217;m busily working on the next version of Cayri, and I&#8217;m pleased to announce that this new version will live directly on your desktop.  A couple weeks ago, I was little unsure if I was going to be able to pull this off, but with some assistance from the guys over at Modest Maps [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m busily working on the next version of <a href="http://www.cayri.org" target="_blank">Cayri</a>, and I&#8217;m pleased to announce that this new version will live directly on your desktop.  A couple weeks ago, I was little unsure if I was going to be able to pull this off, but with some assistance from the guys over at <a href="http://modestmaps.com/" target="_blank">Modest Maps</a> and the new <a href="http://labs.adobe.com/technologies/air/" target="_blank">AIR</a> runtime, it&#8217;s all possible.  Here&#8217;s a break down of the new features:</p>
<p><strong>Different Map Views</strong><br />
You can now switch between either Google Maps, Yahoo Maps, or Microsoft&#8217;s Virtual Earth.  On top of that, you will also be able to toggle between road, aerial, and hybrid views.  What&#8217;s great about hybrid view, is that the map will display country boundaries and also display aerial photography.  I think that people will also enjoy using Google instead of Yahoo because their imagery is more up-to-date.</p>
<p><strong>METAR Weather</strong><br />
Pretty basic - retrieve a weather report for almost any airport in the world by typing in an ICAO code.</p>
<p><strong>Pilot and Controller Details</strong><br />
This was a feature that didn&#8217;t make the previous version, but it&#8217;s finally implemented now.  You can either click on an aircraft or ATC position on the map, or click on a client in the Client Listing window, and a pop-up will appear with the detailed information for that user.</p>
<p><strong>User Settings</strong><br />
Since Cayri now lives on your desktop, you will be able to store user settings.  This means Cayri can store the position of the map, or save a collection of your favorite map filters.</p>
<p>I haven&#8217;t set a release date yet, but I&#8217;m hoping for sometime in mid August.  Make sure to check back soon, as I will be posting screen shots of Cayri running on Mac OSX and in Windows.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/07/16/cayri-on-your-desktop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>No Dice with Yahoo Maps and AIR</title>
		<link>http://www.intriguemedia.net/2007/06/24/no-dice-with-yahoo-maps-and-air/</link>
		<comments>http://www.intriguemedia.net/2007/06/24/no-dice-with-yahoo-maps-and-air/#comments</comments>
		<pubDate>Sun, 24 Jun 2007 19:12:16 +0000</pubDate>
		<dc:creator>Dan Schultz</dc:creator>
		
		<category><![CDATA[AIR]]></category>

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

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

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

		<guid isPermaLink="false">http://www.intriguemedia.net/?p=21</guid>
		<description><![CDATA[Spending the last couple weeks refactoring Cayri&#8217;s code to be more modular, I was excited to start working on the AIR version of Cayri this morning.  So I started up Flex Builder, drug my custom Yahoo Maps control onto the canvas, compiled the project, and got this sweet error:
Error: Error #2067: The ExternalInterface is [...]]]></description>
			<content:encoded><![CDATA[<p>Spending the last couple weeks refactoring Cayri&#8217;s code to be more modular, I was excited to start working on the AIR version of <a href="http://www.intriguemedia.net/cayri-project">Cayri</a> this morning.  So I started up Flex Builder, drug my custom Yahoo Maps control onto the canvas, compiled the project, and got this sweet error:<code></code></p>
<p><code>Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.</code></p>
<p>This is just a heads up to those who are using an ExternalInterface work around for AS2 to AS3 communication, and are planning on moving your projects to AIR.</p>
<p>Ugh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intriguemedia.net/2007/06/24/no-dice-with-yahoo-maps-and-air/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
