<?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>Penguinspeak &#187; Actionscript</title>
	<atom:link href="http://macmartine.com/blog/category/actionscript/feed" rel="self" type="application/rss+xml" />
	<link>http://macmartine.com/blog</link>
	<description>This is how I see it.</description>
	<lastBuildDate>Wed, 09 Dec 2009 23:30:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to loop through properties of a custom object/VO</title>
		<link>http://macmartine.com/blog/2009/11/how-to-loop-through-properties-of-a-custom-objectvo.html</link>
		<comments>http://macmartine.com/blog/2009/11/how-to-loop-through-properties-of-a-custom-objectvo.html#comments</comments>
		<pubDate>Fri, 13 Nov 2009 22:29:46 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=150</guid>
		<description><![CDATA[If you just have a plain ol boring object, you can loop through it with a basic for&#8230;in: var myObj:Object = {x:1, y:5}; for (var i:String in myObj) { trace(i + ": " + myObj[i]); } However, if you have a custom value object, that doesn&#8217;t quite work. But what you can do is use [...]]]></description>
			<content:encoded><![CDATA[<p>If you just have a plain ol boring object, you can loop through it with a basic for&#8230;in:</p>
<pre name="code" class="javascript">
var myObj:Object = {x:1, y:5};
for (var i:String in myObj)
{
    trace(i + ": " + myObj[i]);
}
</pre>
<p>However, if you have a custom value object, that doesn&#8217;t quite work. But what you can do is use describeType() to create an XMLList version on your VO.</p>
<pre name="code" class="javascript">

var vo : SearchVO = data.getBody() as SearchVO;
// create an XMLList version of the VO
var varList:XMLList = describeType(vo)..variable;

// loop through the property list
for(var i:int; i < varList.length(); i++){
    // output the property name and value
    trace(varList[i].@name+':'+ vo[varList[i].@name]);
}
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=How+to+loop+through+properties+of+a+custom+object%2FVO+http://bit.ly/1MlKGw" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2009/11/how-to-loop-through-properties-of-a-custom-objectvo.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Associative array of U.S. state codes</title>
		<link>http://macmartine.com/blog/2009/11/associative-array-of-u-s-state-codes.html</link>
		<comments>http://macmartine.com/blog/2009/11/associative-array-of-u-s-state-codes.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 16:07:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=139</guid>
		<description><![CDATA[Just in case it&#8217;ll save anyone some time some day&#8230; var _stateCodes : Array = new Array(); _stateCodes["AL"] = "Alabama"; _stateCodes["AK"] = "Alaska"; _stateCodes["AS"] = "American Somoa"; _stateCodes["AZ"] = "Arizona"; _stateCodes["AR"] = "Arkansas"; _stateCodes["CA"] = "California"; _stateCodes["CO"] = "Colorado"; _stateCodes["CT"] = "Connecticut"; _stateCodes["DE"] = "Delaware"; _stateCodes["DC"] = "District Of Columbia"; _stateCodes["FM"] = "Federated States of [...]]]></description>
			<content:encoded><![CDATA[<p>Just in case it&#8217;ll save anyone some time some day&#8230;</p>
<pre name="code" class="xml">

			var _stateCodes : Array = new Array();
			_stateCodes["AL"] = "Alabama";
			_stateCodes["AK"] = "Alaska";
			_stateCodes["AS"] = "American Somoa";
			_stateCodes["AZ"] = "Arizona";
			_stateCodes["AR"] = "Arkansas";
			_stateCodes["CA"] = "California";
			_stateCodes["CO"] = "Colorado";
			_stateCodes["CT"] = "Connecticut";
			_stateCodes["DE"] = "Delaware";
			_stateCodes["DC"] = "District Of Columbia";
			_stateCodes["FM"] = "Federated States of Micronesia";
			_stateCodes["FL"] = "Florida";
			_stateCodes["GA"] = "Georgia";
			_stateCodes["GU"] = "Guam";
			_stateCodes["HI"] = "Hawaii";
			_stateCodes["ID"] = "Idaho";
			_stateCodes["IL"] = "Illinois";
			_stateCodes["IN"] = "Indiana";
			_stateCodes["IA"] = "Iowa";
			_stateCodes["KS"] = "Kansas";
			_stateCodes["KY"] = "Kentucky";
			_stateCodes["LA"] = "Lousiana";
			_stateCodes["ME"] = "Maine";
			_stateCodes["MH"] = "Marshall Islands";
			_stateCodes["MD"] = "Maryland";
			_stateCodes["MA"] = "Massachussetts";
			_stateCodes["MI"] = "Michigan";
			_stateCodes["MN"] = "Minnesota";
			_stateCodes["MS"] = "Mississippi";
			_stateCodes["MO"] = "Missouri";
			_stateCodes["MT"] = "Montana";
			_stateCodes["NE"] = "Nebraska";
			_stateCodes["NV"] = "Nevada";
			_stateCodes["NH"] = "New Hampshire";
			_stateCodes["NJ"] = "New Jersey";
			_stateCodes["NM"] = "New Mexico";
			_stateCodes["NY"] = "New York";
			_stateCodes["NC"] = "North Carolina";
			_stateCodes["ND"] = "North Dakota";
			_stateCodes["MP"] = "Northern Mariana Islands";
			_stateCodes["OH"] = "Ohia";
			_stateCodes["OK"] = "Oklahoma";
			_stateCodes["OR"] = "Oregon";
			_stateCodes["PW"] = "Palau";
			_stateCodes["PA"] = "Pennsylvania";
			_stateCodes["PR"] = "Puerto Rico";
			_stateCodes["RI"] = "Rhode Island";
			_stateCodes["SC"] = "South Carolina";
			_stateCodes["SD"] = "South Dakota";
			_stateCodes["TN"] = "Tennessee";
			_stateCodes["TX"] = "Texas";
			_stateCodes["UT"] = "Utah";
			_stateCodes["VT"] = "Vermont";
			_stateCodes["VI"] = "Virgin Islands";
			_stateCodes["VA"] = "Virginia";
			_stateCodes["WA"] = "Washington";
			_stateCodes["WV"] = "West Virginia";
			_stateCodes["WI"] = "Wisconsin";
			_stateCodes["WY"] = "Wyoming";
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Associative+array+of+U.S.+state+codes+http://bit.ly/ExMOj" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2009/11/associative-array-of-u-s-state-codes.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Actionscript 3- Vector to Array</title>
		<link>http://macmartine.com/blog/2009/02/actionscript_3_vector_to_array.html</link>
		<comments>http://macmartine.com/blog/2009/02/actionscript_3_vector_to_array.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 20:16:04 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=37</guid>
		<description><![CDATA[There&#8217;s currently no way to convert a Vector to an Array (or ArrayCollection), so here&#8217;s a simple util that&#8217;ll do it. Accepts any type within the Vector, so the parameter is just an Object, then we convert it back to a vector before the Array conversion. Phew. public static function VectorToArray( v:Object ):Array { var [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s currently no way to convert a Vector to an Array (or ArrayCollection), so here&#8217;s a simple util that&#8217;ll do it. Accepts any type within the Vector, so the parameter is just an Object, then we convert it back to a vector before the Array conversion. Phew.</p>
<pre name="code" class="java">
public static function VectorToArray( v:Object ):Array
{
    var vec : Vector.<object> = Vector.<object>(v);
    var arr : Array = new Array()
    for each( var i : Object in vec ) {
        arr.push(i);
    }
    return arr;
}
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Actionscript+3-+Vector+to+Array+http://bit.ly/2HXX2" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2009/02/actionscript_3_vector_to_array.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Data storage and caching with SQLite databases and Adobe AIR</title>
		<link>http://macmartine.com/blog/2008/02/data_storage_and_caching_with_.html</link>
		<comments>http://macmartine.com/blog/2008/02/data_storage_and_caching_with_.html#comments</comments>
		<pubDate>Tue, 12 Feb 2008 14:45:43 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=26</guid>
		<description><![CDATA[You may or may not know by now that the AIR runtime includes a version of SQLite engine. Being a smaller implementation of SQL, SQLite supports all your usual database transactions, a lot of the complex queries, and triggers. With it,you can create a database to store all the data for your Flex/AIR desktop applications, [...]]]></description>
			<content:encoded><![CDATA[<p>You may or may not know by now that the AIR runtime includes a version of SQLite engine. Being a smaller implementation of SQL, SQLite supports all your usual database transactions, a lot of the complex queries, and triggers. With it,you can create a database to store all the data for your Flex/AIR desktop applications, store data for offline use of your Flex/AIR desktop/web applications, or for caching of data. It&#8217;s all done in the same way. I was recently working on an application where I wanted the user to have an option to be logged in automatically when the app was launched, so the first time the user logged in I created a database to cache that login info. From then on when the application is launched it checks to see if the database exists, and if so it grabs the login info, and logs them in automatically.</p>
<p>I&#8217;ve made a simple example which is a super simple desktop application which stores it&#8217;s data in a SQLite database. The idea and implementation here is very similar to what I just described for the caching example. On launch, we first check to see if the database exists. If it does, that means it ought to contain some data so we grab the data and display it. If the database doesn&#8217;t exist, we create it and add our one default entry, then load it into the application. The user can then add, remove, and update entries. When each of these transactions sends a result of success, we reload all the data in the database. Obviously in a real-world application this wouldn&#8217;t be a great idea; that&#8217;s too much overhead. One option would be to just manipulate the dataProvider ArrayCollection after each successful transaction &#8212; but for this simple example I&#8217;m leaving it the way it is for the intent of simply demonstrating using SQLite.</p>
<p>At this point I think I&#8217;ll let the code speak for itself.</p>
<p>ﾠ<br />
Basically you&#8217;ll notice the basic steps are:</p>
<p>1. Create a connection: connection = new SQLConnection();</p>
<p>2. Define the database file: dbFile = File.applicationStorageDirectory.resolvePath(dbFileString);</p>
<p>3. Open (or create and open ) the database: connection.open(dbFile);</p>
<p>4. Create an empty SQLStatement: var sql : SQLStatement = new SQLStatement();</p>
<p>5. Create a query: var sqlString : String = &#8220;CREATE TABLE Users (&#8221; +</p>
<p>&#8221; uid INTEGER PRIMARY KEY AUTOINCREMENT, &#8221; +</p>
<p>&#8221; name TEXT, &#8221; +</p>
<p>&#8221; phonenumber TEXT)&#8221;;</p>
<p>6. Attach the connection and the query to the SQLStatement:</p>
<p>sql.sqlConnection = connection;</p>
<p>sql.text = sqlString;</p>
<p>7. Create event listeners for success and failure:</p>
<p>sql.addEventListener(SQLEvent.RESULT, onDBCreateTableResult);</p>
<p>sql.addEventListener(SQLErrorEvent.ERROR, onDBCreateTableError);</p>
<p>8. Execute! : sql.execute()</p>
<p>ﾠ</p>
<pre name="code" class="xml">

 <?xml version="1.0" encoding="utf-8"?>
 <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 width="438" height="251"
 creationComplete="onCreationComplete()">
 <mx:Script>
 <!--[CDATA[
 import mx.controls.Alert;
 import mx.events.DataGridEvent;
 import mx.collections.ArrayCollection;
 [Bindable] public var dp : ArrayCollection = new ArrayCollection();
 private var connection : SQLConnection;
 public var dbStatement : SQLStatement;
 public var dbFile : File;
 public var dbFileString : String = "exampledb.db";
 public function onCreationComplete():void
 {
 connection = new SQLConnection();
 dbFile = File.applicationStorageDirectory.resolvePath(dbFileString);
 // does the database exist?
 if( dbFile.exists )
 {
 // the database exists, so let's open it and read in the data
 connection.open(dbFile);
 loadData();
 } else {
 // the database does not exists, so let's create it
 createDB();
 }
 }
 public function createDB() : void
 {
 connection.addEventListener(SQLEvent.OPEN, onDBCreateResult);
 connection.addEventListener(SQLErrorEvent.ERROR, onDBError);
 // the following line creates the database if it does not exists, but we already know it doesn't
 connection.open(dbFile);
 }
 private function onDBCreateResult(event:SQLEvent):void
 {
 // we successfully created the database, so let's create our table
 createTable();
 }
 /*
 For this example we can use this error result handler for all our transactions
 */
 private function onDBError(event:SQLErrorEvent):void
 {
 Alert.show( event.error.name + " " + event.error.errorID + "\n" + event.error.details + "\n" + event.error.message);
 }
 public function createTable() : void
 {
 var sql : SQLStatement = new SQLStatement();
 sql.sqlConnection = connection;
 var sqlString : String = "CREATE TABLE Users (" +
 " uid INTEGER PRIMARY KEY AUTOINCREMENT, " +
 " name TEXT, " +
 " phonenumber TEXT)";
 sql.text = sqlString;
 sql.addEventListener(SQLEvent.RESULT, onDBCreateTableResult);
 sql.addEventListener(SQLErrorEvent.ERROR, onDBCreateTableError);
 sql.execute();
 sqlString = "INSERT INTO Users ( name, phonenumber) " +
 "VALUES ( 'Mac Martine', '555-1212')";
 sql.text = sqlString;
 //sql.addEventListener(SQLEvent.RESULT, onDBAddResult);
 sql.addEventListener(SQLErrorEvent.ERROR, onDBError);
 sql.execute();
 }
 private function onDBCreateTableResult(event:SQLEvent):void
 {
 trace('table created');
 loadData();
 }
 private function onDBCreateTableError(event:SQLErrorEvent):void
 {
 Alert.show( event.error.name + " " + event.error.errorID + "\n" + event.error.details + "\n" + event.error.message);
 trace( event.error.name + " " + event.error.errorID + "\n" + event.error.details + "\n" + event.error.message);
 }
 private function loadData():void
 {
 dbStatement = new SQLStatement();
 dbStatement.sqlConnection = connection;
 var sqlQuery:String = "select * from Users";
 dbStatement.text = sqlQuery;
 dbStatement.addEventListener(SQLEvent.RESULT, onRetrieveDataResult);
 dbStatement.addEventListener(SQLErrorEvent.ERROR, onDBError);
 dbStatement.execute();
 }
 private function onRetrieveDataResult(event:SQLEvent):void
 {
 var result : SQLResult = dbStatement.getResult();
 dp = new ArrayCollection();
 for each( var el : Object in result.data )
 {
 dp.addItem( { uid: el.uid, name: el.name, phonenumber: el.phonenumber } );
 }
 trace('cache retrieved');
 }
 public function add():void
 {
 var sql : SQLStatement = new SQLStatement();
 sql.sqlConnection = connection;
 dbStatement = new SQLStatement();
 dbStatement.sqlConnection = connection;
 var sqlString : String = "INSERT INTO Users ( name, phonenumber) " +
 "VALUES ( '(edit me)', '555-1212')";
 sql.text = sqlString;
 sql.addEventListener(SQLEvent.RESULT, onDBAddSuccess);
 sql.addEventListener(SQLErrorEvent.ERROR, onDBError);
 sql.execute();
 }
 public function onDBAddSuccess( event : SQLEvent ):void
 {
 var result : SQLResult = dbStatement.getResult();& lt;br /> var uid : Number = event.currentTarget.sqlConnection.lastInsertRowID;& lt;br /> loadData();
 }
 public function remove():void
 {
 var selectedItemUid : Number = dg.selectedItem.uid;& lt;br /> var selectedIndex : Number = dg.selectedIndex;<br /& gt; if( selectedIndex >= 0 )
 {<br /& gt; var sql : SQLStatement = new SQLStatement();<br /& gt; sql.sqlConnection = connection;<br /& gt; dbStatement = new SQLStatement();<br /& gt; dbStatement.sqlConnection = connection;<br /& gt; ﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠﾠvar sqlString : String = "DELETE FROM Users WHERE uid=" + selectedItemUid;& lt;br /> sql.text = sqlString;
 sql.addEventListener(SQLEvent.RESULT, onDBRemoveResult);
 sql.addEventListener(SQLErrorEvent.ERROR, onDBError);
 sql.execute();
 } else {
 Alert.show("You do not have a row selected to delete.");
 }
 }
 public function onDBRemoveResult( event : SQLEvent ):void
 {
 loadData();
 }
 public function update( event : DataGridEvent ):void
 {
 var sql : SQLStatement = new SQLStatement();
 sql.sqlConnection = connection;
 dbStatement = new SQLStatement();
 dbStatement.sqlConnection = connection;
 var sqlString : String = "UPDATE Users SET name = '" + event.itemRenderer.data.name + "' WHERE uid = " + event.itemRenderer.data.uid;
 sql.text = sqlString;
 //sql.addEventListener(SQLEvent.RESULT, onDBAddResult);
 sql.addEventListener(SQLErrorEvent.ERROR, onDBError);
 sql.execute();
 }
 ]]-->
 </mx:Script>
 <mx:DataGrid id="dg" dataProvider="{dp}" x="10" y="37" width="407" height="202" editable="true" itemFocusOut="update(event)" >
 <mx:columns>
 <mx:DataGridColumn headerText="Name" dataField="name" editable="true" />
 <mx:DataGridColumn headerText="Phone Number" dataField="phonenumber"/>
 </mx:columns>
 </mx:DataGrid>
 <mx:LinkButton x="300" y="10" label="Add" click="add()"/>
 <mx:LinkButton x="354" y="10" label="Remove" click="remove()"/>
 </mx:WindowedApplication>
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Data+storage+and+caching+with+SQLite+databases+and+Adobe+AIR+http://bit.ly/4sVy4Q" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2008/02/data_storage_and_caching_with_.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>InsideRIA launched today</title>
		<link>http://macmartine.com/blog/2008/01/insideria.html</link>
		<comments>http://macmartine.com/blog/2008/01/insideria.html#comments</comments>
		<pubDate>Mon, 21 Jan 2008 16:27:55 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=25</guid>
		<description><![CDATA[Check out InsideRIA.com which was launched today. It&#8217;s an online community developed by O&#8217;Reilly and sponsored by Adobe, which will provide a number of resources for information about RIA&#8217;s, RIA development, and that which is related, with lots of attention on Flex, AIR, Actionscript and Flash.]]></description>
			<content:encoded><![CDATA[<p>Check out <a href="http://InsideRIA.com">InsideRIA.com</a> which was launched today. It&#8217;s an online community developed by O&#8217;Reilly and sponsored by Adobe, which will provide a number of resources for information about RIA&#8217;s, RIA development, and that which is related, with lots of attention on Flex, AIR, Actionscript and Flash.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=InsideRIA+launched+today+http://bit.ly/1LxY07" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2008/01/insideria.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deferred instantiation of mediators in a PureMVC Flex application</title>
		<link>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html</link>
		<comments>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html#comments</comments>
		<pubDate>Mon, 14 Jan 2008 20:14:39 +0000</pubDate>
		<dc:creator>99miles</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PureMVC]]></category>

		<guid isPermaLink="false">http://macmartine.com/blog/?p=21</guid>
		<description><![CDATA[I&#8217;m creating my first project using PureMVC after using Cairngorm for a few projects. Once I started understanding the concepts and intent behind each of the architecture components (Proxies and Models, Views and Mediators, Controllers and Commands), it&#8217;s been great in it&#8217;s relative simplicity. I did printed out the docs and read over them everyday [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m creating my first project using PureMVC after using Cairngorm for a few projects. Once I started understanding the concepts and intent behind each of the architecture components (Proxies and Models, Views and Mediators, Controllers and Commands), it&#8217;s been great in it&#8217;s relative simplicity. I did printed out the docs and read over them everyday at lunch for a few days in a row just make it all really sink it, but it didn&#8217;t take too long to click.<br />
The best part is that I&#8217;ve had a few questions so I decided to check out the PureMVC forums on the PureMVC site. So far everything I&#8217;ve searched has returned a thread with a very detailed, extensive answer from Cliff! The days go so much easier when there&#8217;s easy to find and good information about whatever your working with.<br />
One of the problems I ran into pretty quickly was that I had a TabNavigator with 3 tabs where the contents aren&#8217;t to be drawn or loaded until they are clicked on.<br />
I initially tried to register the mediators for those 3 view components at startup, which to no surprise threw runtime errors because the views didn&#8217;t yet exist. Not being sure what the best solution was here, I searched the forums and found <a href="http://forums.puremvc.org/index.php?topic=113.0">this thread</a>.<br />
I went with Cliff&#8217;s recommendation (deferred instantiation) and here&#8217;s what I have now:<br />
My TabNavigator has 3 tabs each containing one custom component named &#8220;tags&#8221;, &#8220;groups&#8221;, &#8220;info&#8221;.<br />
In each of these components I have a creationComplete event which calls an onCreationComplete function, which in turn dispatches a custom Event:</p>
<pre name="code" class="java">
dispatchEvent( new ComponentLoadedEvent( ComponentLoadedEvent.COMPONENT_LOADED, true, false, this ) );
</pre>
<p>The mediator of the TabNavigator itself listens for this event and calls handleLoad when it hears it:</p>
<pre name="code" class="java">
mainComponent.addEventListener( ComponentLoadedEvent.COMPONENT_LOADED, handleLoad );
</pre>
<p>The handleLoad() registers the appropriate mediator for the loaded component:</p>
<pre name="code" class="java">
public function handleLoad( e : Event ):void
{
var component :Object 	= e["component"].name;
switch(component)
{
case "tags":
facade.registerMediator( new TagsMediator( mainComponent.tags )  );
break;
case "groups":
facade.registerMediator( new GroupsMediator( mainComponent.groups )  );
break;
case "info":
facade.registerMediator( new UploadStatusMediator( mainComponent.info )  );
break;
}
}
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Deferred+instantiation+of+mediators+in+a+PureMVC+Flex+application+http://bit.ly/nEvOe" title="Post to Twitter"><img class="nothumb" src="http://macmartine.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://macmartine.com/blog/2008/01/deferred_instantiation_of_medi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
