<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>InsideRIA</title>
        <link>http://www.insideria.com/</link>
        <description>InsideRIA.com is an online community developed by O’Reilly and sponsored by Adobe Systems Incorporated. Our goal is to create an invaluable resource for information on the ever-changing state of design and development of rich Internet applications (RIAs).</description>
        <language>en</language>
        <copyright>Copyright 2008</copyright>
        <lastBuildDate>Fri, 09 May 2008 13:30:55 -0800</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Introducing InsideRIA Listen</title>
            <description><![CDATA[You will notice that InsideRIA has added new listen functionality that allows you to listen to each blog post. This is great for people like me who are usually very busy trying to do more than one thing at a time. 

<div class="ap_c"><a href="http://www.insideria.com/upload/2008/05/introducing_insideria_listen/id019.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/introducing_insideria_listen/id019.jpg" alt="Listen" title="Click to enlarge" width="400"/></a><div class="apcaption">The new Listen link</div></div>


Click on the new listen link and a media player will open and begin reading you the post. You also have the option to download a copy of the mp3 file to take with you on your favorite portable devise.

<div class="ap_c"><a href="http://www.insideria.com/upload/2008/05/introducing_insideria_listen/id017.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/introducing_insideria_listen/id017.jpg" alt="Listen Player" title="Click to enlarge" width="400"/></a><div class="apcaption">The new player showing the download link</div></div>

 I recommend you check out this great new feature of InsideRIA.com. You can even try it on this post. :-)





]]></description>
            <link>http://www.insideria.com/2008/05/introducing-insideria-listen.html</link>
            <guid>http://www.insideria.com/2008/05/introducing-insideria-listen.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">News &amp; Events</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">listen</category>
            
            <pubDate>Fri, 09 May 2008 13:30:55 -0800</pubDate>
        </item>
        
        <item>
            <title>Announcing the User Interface Resource Center</title>
            <description><![CDATA[<div class="ap_r" style="margin: 16px;"><a href="http://www.insideria.com/upload/2008/05/announcing_the_user_interface/Picture%202.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/announcing_the_user_interface/Picture%202.png" alt="User Interface Resource Center logo" title="Click to enlarge" width="148"/></a></div>
I happy to announce the launch of a community resource center for user interfaces aptly title the <a href="http://www.uiresourcecenter.com">User Interface Resource Center</a>.  Here's the official description:

"The User Interface Resource Center is a community resource dedicated to providing information, education and resources around the technologies and techniques that make up the world of user interface design, development and rich Internet applications.

Adobe and Microsoft are both UIRC content partners.  We are also inviting other agencies and thought leaders to contribute content and  share their industry insights.  Enterprise companies such as eBay, NASDAQ,  and Discovery Channel have also agreed to share their case studies or be interviewed for the site.      
 
The target audience will be business technology professionals specifically seeking to understand and learn how UI design and technologies can benefit and improve their business and customer experience."

I know the UIRC has a lot of great interviews, white papers, and other good content coming soon.  I've been participating as an editor for the development content, and I can tell you it's going to be good.
 
More about UIRC: 
http://www.uiresourcecenter.com/about-uirc.html?s=8]]></description>
            <link>http://www.insideria.com/2008/05/announcing-the-user-interface.html</link>
            <guid>http://www.insideria.com/2008/05/announcing-the-user-interface.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">News &amp; Events</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">Design</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">resources</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">UIRC</category>
            
            <pubDate>Fri, 09 May 2008 07:00:23 -0800</pubDate>
        </item>
        
        <item>
            <title>Aptana Cloud Makes App Deployment Easy</title>
            <description><![CDATA[<div class="ap_r" style="margin: 16px;"><a href="http://www.insideria.com/upload/2008/05/aptana_cloud_makes_deployment/aptana_cloud_logo_large_0.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/aptana_cloud_makes_deployment/aptana_cloud_logo_large_0.png" alt="aptana_cloud_logo_large_0.png" title="Click to enlarge" width="148"/></a></div>Aptana <a href="http://ajaxian.com/archives/aptana-cloud-develop-on-your-desktop-sync-out-to-the-cloud">announced last week</a> they're going to help developers deploy to the cloud, starting with Joyent's hosting services.  So now Aptana is helping developers write JavaScript code with their IDE, run JavaScript and on the server with Jaxxer and now deploy their app to the web with the click of a button.

<a href="http://blogs.nitobi.com/dave">Dave Johnson</a> and I were in San Francisco for JavaOne so we managed to catch up with Kevin Hakman of Atpana and get a quick demo.  No joke he actually deployed an app to Joyent's hosting environment
in a matter of minutes all from Aptana.  Down the road they plan to support to support other cloud services like Amazon AWS and Google App Engine.  

<object type="application/x-shockwave-flash" data="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fnitobi%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F893376%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" width="400" height="255" allowfullscreen="true" id="showplayer"><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fnitobi%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F893376%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" /><param name="quality" value="best" /><embed src="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fnitobi%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F893376%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" quality="best" width="400" height="255" name="showplayer" type="application/x-shockwave-flash"></embed></object>

From Aptana's site:

<blockquote>Aptana Cloud is a scalable Elastic Application Cloud™ featuring the most popular and widely adopted Web infrastructure, ready to use and ready to scale as you need it. Aptana Cloud also plugs right into your IDE to provide instant deployment, smart synchronization, and seamless migration as you scale. Aptana Cloud is ideal for developers who use scripting languages to create Ajax, Facebook, mySpace and all other sorts of Web applications. </blockquote>

I know a couple of the people on our team use Aptana for Ajax development today but I think we could benefit from Cloud.  Dave and I are very excited to try it out.

<a href="http://www.aptana.com/cloud">Aptana Cloud</a> has an early access program you can sign up for as well get more information <a href="http://www.aptana.com/cloud">here</a>.

]]></description>
            <link>http://www.insideria.com/2008/05/aptana-cloud-makes-deployment.html</link>
            <guid>http://www.insideria.com/2008/05/aptana-cloud-makes-deployment.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">screencasts</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">aptana</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">cloud</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">hosting</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">joyent</category>
            
            <pubDate>Thu, 08 May 2008 14:36:36 -0800</pubDate>
        </item>
        
        <item>
            <title>Call for Questions - SlideRocket</title>
            <description><![CDATA[<div class="ap_r" style="margin: 0 16px 16px 16px;"><a href="http://www.insideria.com/dtucker/sliderocket-large.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/dtucker/sliderocket-small.jpg" alt="SlideRocket Logo" title="Click to enlarge" width="148"/></a></div>

<p>Tomorrow afternoon I am going to be having a chat with a few of the guys from <a href="http://www.sliderocket.com/" target="_blank">SlideRocket</a>.  If you aren't familiar with it - SlideRocket is a Flash/Flex based RIA that really does online presentation creation and delivery right.  They are currently in private beta.  Let me know if there are any questions that you would like me to ask.</p>

<div class="ap_c" style="margin: 16px;"><a href="http://www.insideria.com/dtucker/sliderocket-l.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/dtucker/sliderocket.jpg" alt="SlideRocket" title="Click to enlarge" width="400"/></a><div class="apcaption">SlideRocket Screenshot</div></div>

<h2><strong>SlideRocket Information</strong></h2>
<p>
<a href="http://www.sliderocket.com/blog/" target="_blank">SlideRocket Blog</a><br />
<a href="http://www.techcrunch.com/2008/03/19/sliderocket-presentation-web-app-enters-private-beta-get-your-invite-here-2/" target="_blank">TechCrunch Article</a><br />
<a href="http://scobleizer.com/2008/03/20/vc-admits-he-hates-boring-powerpoints/" target="_blank">Scoble on SlideRocket</a>
</p>
]]></description>
            <link>http://www.insideria.com/2008/05/call-for-questions-sliderocket.html</link>
            <guid>http://www.insideria.com/2008/05/call-for-questions-sliderocket.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">ria</category>
            
            <pubDate>Thu, 08 May 2008 10:42:23 -0800</pubDate>
        </item>
        
        <item>
            <title>AIR API - Creating Tables and Databases</title>
            <description><![CDATA[<div class="ap_r" style="margin: 0 16px 16px 16px;"><a href="http://www.insideria.com/airLogo-Shadow.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/airLogo-Shadow.jpg" alt="airLogo-Shadow.jpg" title="Click to enlarge" width="148"/></a></div>

<p>In the <a href="http://www.insideria.com/2008/04/air-api-additional-query-tech.html">last tutorial</a>, I examined some additional techniques for querying an existing database.  Today I want to explain how you create a database and create a table inside of that database..  If you are good with SQL and have followed along with this series, this concept will work as expected.</p>

<h2><strong>Creating Databases</strong></h2>

<p>I briefly touch on creating databases in a previous tutorial.  The concept is very similar to working with a pre-populated database.  Just as with a pre-populated database you will need to create an instance of the File class that points to a file.  If that file does not exist, then the database will be created when the open or openAsync methods are called.</p>

<div class="acode" style="overflow:auto;padding: 10px;"><div style="overflow-x:visible;">
<mt:CodeBeautify language="actionscript">
...
// Create an instance of the SQLConnection Class
var conn:SQLConnection = new SQLConnection();
// Create an instance of the File Class that points to the file
var db:File = File.applicationStorageDirectory.resolvePath("newDB.db");
// Open the connection - which will create the DB
conn.openAsync( db );
...
</mt:CodeBeautify>
</div></div>

<p>If you do not pass an instance of the File class to the open or openAsync methods, a database is created in memory, and it will remain as long as the application is open.</p>

<h2><strong>Affinity Types</strong></h2>

<p>Before you can create any tables, you will have to know about affinity types (data types) within SQLite.  AIR contains ten different affinity types that can be used:</p>

<ul>
<li>TEXT (also called STRING)</li>
<li>NUMERIC</li>
<li>INTEGER: </li>
<li>REAL (also called NUMBER)</li>
<li>BOOLEAN</li>
<li>DATE</li>
<li>XML</li>
<li>XMLLIST</li>
<li>OBJECT</li>
<li>NONE</li>
</ul>

<p><strong>NOTE:</strong> Each affinity can handle data differently.  You will want to consult the information on Affinity Types in the <a target="_blank" href="http://livedocs.adobe.com/flex/3/langref/localDatabaseSQLSupport.html#columnAffinity">documentation</a> before you design your database schema.</p>

<h2><strong>Creating Tables</strong></h2>

<p>To create tables within AIR, you simply need to execute an SQLStatement just as you did to query the data.  For example, let's say that you wanted to create a table names 'Contacts' with the following fields:</p>

<ol style='list-style-type: decimal'>
<li>firstName: This will just be a string</li>
<li>lastName: This will just be a string</li>
<li>age: This will be a uint</li>
<li>gender: This will be a Boolean value</li>
</ol>

<p>The table is created in the example below:</p>

<div class="acode" style="overflow:auto;padding: 10px;"><div style="overflow-x:visible;">
<mt:CodeBeautify language="actionscript">
private function init():void {

	dbFile = File.applicationDirectory.resolvePath( "contacts.db" );
	conn = new SQLConnection();
	conn.addEventListener(SQLEvent.OPEN, openSuccess);
	conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
	conn.openAsync( dbFile );

}

private function openSuccess( event:SQLEvent ):void {
	createTable();
}

private function openFailure( event:SQLEvent ):void {
	throw new Error( 'Database Connection Failed' );
}

private function createTable():void {
	
	var q:SQLStatement = new SQLStatement();
	q.sqlConnection = conn;
	
	var sql:String = "CREATE TABLE IF NOT EXISTS contacts( " +
				"firstName TEXT, " +
				"lastName TEXT, " +
				"age INTEGER, " +
				"gender BOOLEAN )";
					
	q.text = sql;
	q.addEventListener( SQLEvent.RESULT, queryResult );
	q.addEventListener( SQLErrorEvent.ERROR, queryError );
	q.execute();
	
}

private function queryError( event:SQLErrorEvent ):void {
	trace( 'Create Table Failed' );
}

private function queryResult( event:SQLEvent ):void {
	trace( 'Query Created Successfully' );
}

</mt:CodeBeautify>
</div></div>

<p>The actual SQL statement is found inside of the createTable method.  There are a few things that could have been added to this table (such as an auto-incrementing ID field), but hopefully now you feel comfortable creating tables with the embedded SQLite database in AIR.</p>

<h2><strong>Deleting Tables</strong></h2>

<p>If you are in a situation where you need to delete a table, you will need to execute the following SQLStatement:</p>

<div class="acode" style="overflow:auto;padding: 10px;"><div style="overflow-x:visible;">
<mt:CodeBeautify language="actionscript">
DROP TABLE IF EXISTS contacts;
</mt:CodeBeautify>
</div></div>

<p>If you omit the 'IF EXISTS' portion of the query, and the table does not exists (for example, if it was already deleted) the query response will be an error.</p>

<h2><strong>Resources</strong></h2>

<p>
<a href="http://livedocs.adobe.com/flex/3/langref/localDatabaseSQLSupport.html#columnAffinity" target="_blank">Column Affinity Descriptions</a><br />

</p>]]></description>
            <link>http://www.insideria.com/2008/05/air-api-creating-tables-and-in.html</link>
            <guid>http://www.insideria.com/2008/05/air-api-creating-tables-and-in.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">air</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">air api</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">sqlite</category>
            
            <pubDate>Thu, 08 May 2008 09:31:47 -0800</pubDate>
        </item>
        
        <item>
            <title>Adobe Open Screen - It&apos;s getting there.</title>
            <description><![CDATA[RJ blogged a bit earlier, but I thought I'd share a couple of my thoughts too.  I guess we all knew this would come eventually, <a href="http://blog.digitalbackcountry.com/?p=1404">Flash is more open</a> thanks to the <a href="http://www.openscreenproject.org/">Open Sceen Project</a>.Here's the skinny on the what new licensing entails:

- Removing restrictions on use of the SWF and FLV/F4V specifications
- Publishing the device porting layer APIs for Adobe Flash Player
- Publishing the Adobe Flash® Cast™ protocol and the AMF protocol for robust data services
- Removing licensing fees - making next major releases of Adobe Flash Player and Adobe AIR for devices free

The biggest implication of this is that it's now possible, and likely already underway, to port the Flash Player to other devices such as phones and other personal electronics. What was your second reaction to the iPhone?  Mine was "does it run Flash?" and I don't think I was alone.  Actually could we get in on the Blackberry first...maybe some of my fellow Canadians are already on it.  Let's hope so:)

For large organizations and governments just the possibility of creating an alternative runtime is big enough benefit to make this announcement noteworthy.  

Let's keep in mind that even though the spec is open and free that doesn't mean it's small job to recreate the Flash Player, after all some of the brightest minds in the industry have been working on it for over 10yrs.  Most attempts to recreate it will be slower, bigger and buggier...especially in the early days.  The flip side is that the bright mind of the Flash community can now look through the spec and provide feedback to Adobe. 

One thing to note as <a href="http://almaer.com/blog/being-open-is-hard-as-we-have-seen-this-week">Dion points out</a> is that the license hasn't been published yet, so let's hope there's no surprises in there. 
<blockquote>
Unfortunately, when I looked into the details, there wasn&#8217;t much to see. The claim was that the FLV/SWF/F4V binary formats will be Open, and there will no longer be the restriction that said you can&#8217;t RUN the code.

The problem was that there was no license to go along with this claim, which means that we can&#8217;t actually do much with it yet. Adobe isn&#8217;t more &#8220;Open&#8221; today than it was the day before the announcement. This will hopefully change very soon when we actually see the license, and hopefully see even more.</blockquote>

I know there a lot of critics out there saying this isn't good enough, but it's a step in the right direction.  I'm sure the license details will be forthcoming.

Like giving the PDF spec to ISO, Tamarin to Mozilla and open sourcing Flex Adobe is making great strides at becoming more open.  It's great to have momentum in this direction from one of leaders in the RIA space.  It's going to be a while before the impact of this is felt, building new runtimes and getting them distributed just takes time.  It's going to happen though.]]></description>
            <link>http://www.insideria.com/2008/05/adobe-open-screen-opening-the.html</link>
            <guid>http://www.insideria.com/2008/05/adobe-open-screen-opening-the.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Standards</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">flash</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">openscreen</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">opensource</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">swf</category>
            
            <pubDate>Wed, 07 May 2008 17:14:18 -0800</pubDate>
        </item>
        
        <item>
            <title>Learning From Others</title>
            <description><![CDATA[The best way to learn Flex is to get in there, and to start working with it.  However, there are things you might not pick up on on your own.   One of the best ways to get to know the inner workings of the Flex framework, and to learn how others do it.  Now, where can you look to see how others have done things? Here are a few ideas... 

<u><strong>Open Source Software</strong></u>

First and foremost, the Flex SDK is open source.   The SDK source is distributed with Flex Builder, and is also available on <a href="http://opensource.adobe.com/" target="_blank">http://opensource.adobe.com/</a>.  There are a lot of things you can learn by reviewing the framework source code.  Everything from component life cycle, event usage, to customized rendering and the display list.   Rather than blindly accepting that the components work, you can dive into the component framework and learn HOW it works.   Review the framework!

There are also some other great open source projects out there to help expand your knowledge and capabilities with the framework.

<strong>CoreLib </strong>- The AS3 corelib project is a set of ActionScript classes that are very useful.  This is AS3, not just Flex, but completely usable within Flex applications.  This includes MD5 hashing, RSS/ATOM parsers, JSON parsers, cryptography libraries, among others...
<a href="http://code.google.com/p/as3corelib/" target="_blank">http://code.google.com/p/as3corelib/</a></li>

<strong>FlexLib </strong>- "The FlexLib project is a community effort to create open source user interface components for Adobe Flex 2 and 3." (from the <a href="http://code.google.com/p/flexlib/" target="_blank">FlexLib Wiki</a>)  There are lots of useful components in here.
<a href="http://code.google.com/p/flexlib/" target="_blank">http://code.google.com/p/flexlib/</a>

<strong>Degrafa </strong>- The focus behind the Declarative Graphics Framework (Degrafa) is to bring the graphics classes up a level to provide a common ground between developer and designer within Flex, and enable the graphics classes to become first class citizens within the Flex framework. (from <a href="http://www.degrafa.com/">Degrafa website</a>)   

Degrafa is a great way to learn and incorporate programmatic drawing within Flex applications.   There's also a great intro to Degrafa available at <a href="http://www.insideria.com/2008/05/an-introduction-to-degrafa-1.html">http://www.insideria.com/2008/05/an-introduction-to-degrafa-1.html</a>
<a href="http://www.degrafa.com/">http://www.degrafa.com/</a>

<strong>Papervision, Away3d, etc...  </strong>
There are some great 3d open source frameworks worth checking out.   
<a href="http://blog.papervision3d.org//">http://blog.papervision3d.org/</a>
<a href="http://away3d.com/">http://away3d.com/</a>

There's a great intro to papervision3d introductory article available at:  <a target="_blank" href="http://www.insideria.com/2008/02/papervision3d-part-1-foundatio.html">http://www.insideria.com/2008/02/papervision3d-part-1-foundatio.html</a>

<u><strong>Blogs...</strong></u>
Not quite open source, but you can learn a lot from them.   Read blogs to learn from others, and to keep up with the pulse of the industry.   I most commonly read <a href="http://feeds.adobe.com/" target="_blank">Adobe Feeds (formerly MXMA)</a>, but there are others too.

<u><strong>Newsgroups</strong></u>
<a href="http://tech.groups.yahoo.com/group/flexcoders/" target="_blank">Flexcoders</a> is a great place place on the web to find answers to your Flex questions.  Go there, read other people's posts, learn from them, answer questions if you know the answer, and ask questions if you have them.

<u><strong>User Groups</strong></u>
User groups are a great way to interact with other developers, learn from experts, and discuss technology.   Find a user group near you at: <a href="http://www.adobe.com/cfusion/usergroups/" target="_blank">http://www.adobe.com/cfusion/usergroups/</a>

If you have some other resources, please share them!

___________________________________
<strong>Andrew Trice</strong>
Principal Architect
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems
http://www.cynergysystems.com</a>


]]></description>
            <link>http://www.insideria.com/2008/05/learning-from-others.html</link>
            <guid>http://www.insideria.com/2008/05/learning-from-others.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">flex</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">learning</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">open source</category>
            
            <pubDate>Tue, 06 May 2008 18:22:13 -0800</pubDate>
        </item>
        
        <item>
            <title>Flex 4, states, and bad MXML</title>
            <description><![CDATA[Ted Patrick has a post up on his blog about a new feature in Flex 4 that will allow for state-specific variables to be nested in individual components.  Ted claims that in Flex 3 and below, States have been too hard to use and edit outside of the "design view" (someone uses the design view?), so an effort has been made to simplify them.  The new code posted on Ted's blog looks something like this:

<strong>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="library:ns.adobe.com/flex/halo" 
   xmlns:m="http://ns.adobe.com/mxml/2009" layout="absolute"&gt;

    &lt;m:states&gt;
        &lt;m:State name="landState"/&gt;
        &lt;m:State name="airState"/&gt;
        &lt;m:State name="waterState"/&gt;

    &lt;/m:states&gt;
    &lt;mx:VBox id="vbox"&gt;
        &lt;mx:HBox&gt;
            &lt;mx:Button id="land" label="Land" click="currentState='landState'" /&gt;

            &lt;mx:Button id="air" label="Air" click="currentState='airState'" /&gt;
            &lt;mx:Button id="water" label="Water" click="currentState='waterState'" /&gt;

        &lt;/mx:HBox&gt;
        &lt;mx:CheckBox label="Helicopter" color.airState="0xFF0000"/&gt;
        &lt;mx:CheckBox label="Motorcycle" color.landState="0xFF0000" /&gt;

        &lt;mx:CheckBox label="Car" color.landState="0xFF0000" /&gt;
        &lt;mx:CheckBox label="Airplane" color.airState="0xFF0000"/&gt;

        &lt;mx:CheckBox label="Train" color.landState="0xFF0000" /&gt;
        &lt;mx:CheckBox label="Boat" color.waterState="0xFF0000"/&gt;

        &lt;mx:CheckBox label="Submarine" color.waterState="0xFF0000"/&gt;
    &lt;/mx:VBox&gt;
&lt;/mx:Application&gt;
</strong>
I'm sure this will go fine, but as a person resistant to any language change that can create bad code, I'm worried about how many of these state-specific variables we're going to see.  Imagine if one of his check boxes was written like this:

<strong>&lt;mx:CheckBox id="changeWithState" color.waterState="0xFF0000" color.landState="0xF0F000" color.airState="0xFF0000" /&gt;</strong>

Now, this is no big deal, but if we add a few more states, it'd get unwieldy.  And we really wouldn't want these colors hard-coded into the MXML, which means should be assigned on a model somewhere, so now the code looks like this:

<strong>&lt;mx:CheckBox id="changeWithState" color.waterState="{Model.WATER_COLOR}" color.landState="{Model.LAND_COLOR}" color.airState="{Model.AIR_COLOR}" /&gt;</strong>

And this is probably even worse, because MXML doesn't distinguish between <em>assigned</em> data and <em>bound</em> data, so all of these colors are bound to the model whether we need it or not creating a slough of meaningless getter and setter methods that our compiler will have to sludge through.

In my opinion, a better way to assign these properties would be in ActionScript, where the code is more clear and no binding is required.  All our MXML would bind to is a single model object, like this:

<strong>&lt;mx:Model id="checkBoxStateModel"&gt;
	&lt;color&gt;
		&lt;airState&gt;0xff0000&lt;/airState&gt;
		&lt;waterState&gt;0x00ff00&lt;/waterState&gt;
		&lt;landState&gt;0x0000ff&lt;/landState&gt;
	&lt;/color&gt;
&lt;/mx:Model&gt;

&lt;myCode:StatableCheckBox id="changeWithState" stateModel="{checkBoxStateModel}"/&gt;</strong>

Then write your checkbox in actionscript to parse it's model, subscribe for a parents' stateChange events, and adjust it's properties accordingly.  A base "statableObject" class could be written to handle the state-parsing and property-updating and be reused in multiple places.

I like this solution better for a number of reasons: it keeps our MXML cleaner, makes a cool reusable "statable" object, and allows us to externalize the state-specific data in a model object without adding lots of unnecessary binding to our code.

Have said all of that, I guess Ted's solution is still a huge improvement over the current slough of "addChild" / "removeChild" tags that states require.]]></description>
            <link>http://www.insideria.com/2008/05/flex-4-states-and-bad-mxml.html</link>
            <guid>http://www.insideria.com/2008/05/flex-4-states-and-bad-mxml.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">flex</category>
            
            <pubDate>Tue, 06 May 2008 09:29:04 -0800</pubDate>
        </item>
        
        <item>
            <title>An Introduction to Degrafa</title>
            <description><![CDATA[<div class="ap_r" style="margin: 16px;"><a href="http://www.insideria.com/upload/2008/04/an_introduction_to_degrafa_1/degrafa-code-banner.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/04/an_introduction_to_degrafa_1/degrafa-code-banner.jpg" alt="degrafa-code-banner.jpg" title="Click to enlarge" width="148"/></a></div>One of the most important aspects of delivering a rich user experience is what a user sees and interacts with on the screen. Graphics, whether static or dynamic, comprise the face of an application. Static graphics can definitely suffice for creating the necessary visual parts of an application, but to change them you must replace them with other static graphics. Dynamic graphics, created with programmatic drawing are very powerful because it can be manipulated at run-time, but it can involve more advanced knowledge of the Drawing API. Degrafa is a declarative graphics framework that aims to offer the best of both worlds.<br/>
<br/>
In this article you will be introduced to some of the theory behind Degrafa, the basics of composition, advanced implementations, and how the framework may fit into your Flex or AIR projects. There are many uses for Degrafa, all of which can&#8217;t be covered in this article, but the hope is that this information may reveal something useful for you.<br/>
<br/>
Degrafa is an open-source project created by developers in the RIA community. One of the primary goals is to allow designers and developers to forego the complexities of ActionScript to create dynamic graphics in MXML markup. With Degrafa you can define fills, strokes, shapes, complex paths, and more in the same way you would define a Flex component in MXML. Degrafa can be used to create skins, data visualizations, maps, or meet any other graphics need.<br/>
<br/>
<strong>Some of the features of Degrafa include:</strong><br/>
<br/>
•	A library of pre-composed shapes for you to use as well as the ability to create your own.<br/>
•	Use SVG path data to create complete reusable shapes.<br/>
•	Flexible options for fills and strokes. <br/>
•	Binding of properties for Fills, Strokes and Geometry.<br/>
•	Advanced CSS support for layered backgrounds, complex border control and background image positioning based on CSS 3.<br/>
•	Productive features like derivatives, composition reuse, shape libraries, repeaters, and other utilities that allow you to do more with less code.<br/>
•	Light weight model-based architecture.<br/>
•	Compatibility with Flex 2 and Flex 3.<br/>
•	A "pay-as-you-go" implementation.<br/>
•	Much, much more...<br/>
<br/><br/>
<strong>Terminology</strong><br/>
In the following examples there will be terminology used that you may or may not be familiar with. Some terms revolve around graphics, Flex, or the tags used in Degrafa. Before you get started, here's some definitions of some of those terms you'll see used in the remainder of this article:<br/>
<br/>
<strong>geometry</strong> - A general term referring to any shape, path or graphic.<br/>
<br/>
<strong>graphics context</strong> - A drawing destination where vector drawing commands can occur and stores information on how commands get rendered like line styles or fill styles. Any objects derived from Shape, Sprite or Movie Clip have a graphics property.  Anything visual is drawn to or stored within a graphics context.<br/>
<br/>
<strong>graphicsTarget</strong> - A property available to Degrafa geometry, like Circle, RegularRectangle, Polygon, etc. It allows you to specify the target(s)  as a destination for Degrafa to render to. Acceptable targets must have a graphics context.<br/>
<br/>
<strong>Surface</strong> - A tag in Degrafa provided as a base UIComponent for composing Degrafa elements.<br/>
<br/>
<strong>GeometryGroup</strong> - A tag is used within the Surface tag and allows you to group Degrafa objects together. GeometryGroup is based on Sprite, so you can take advantage of the properties and events supported by Sprite.<br/>
<br/>
<strong>GeometryComposition</strong> - A Degrafa tag that works similarly to GeometryGroup, but it allows you to compose or group elements at any level within your MXML  file, including the root. You can optionally render those graphics to any object containing a graphics property using the graphicsTarget property. <br/>
<br/>
<strong>Fill</strong> - A fill is a graphics term for the treatment of the inner area of an object. Fills are applied to the shapes you create. Degrafa has a variety of fills you can take advantage of like Solid, Linear Gradient, Radial Gradient, Bitmap, Blend and Complex fills.<br/>
<br/>
<strong>Stroke</strong> - A stroke is a graphics term for the treatment of the edge of an object, usually defined with a thickness. Degrafa provides Solid, Linear Gradient and Radial Gradients strokes.<br/>
<br/><br/>
<strong>Getting Started with Degrafa</strong><br/>
To use Degrafa in your projects you have two options; you can either download the latest version of Degrafa as a compiled SWC, or tap in directly to the Degrafa SVN. Both of these options are hosted openly on <a href="http://code.google.com/p/degrafa/" target="_blank">Google Code</a>. For the purposes of this article you can use the compiled Degrafa SWC by following these steps:<br/>
<br/><br/>
1.	Go to Google Code where the Degrafa code is hosted and download the latest version of the Degrafa SWC for the version of Flex you&#8217;re running. There is a version for Flex 2 and Flex 3.  After you&#8217;ve downloaded the Degrafa SWC, open up Flex Builder and create a new project called DegrafaExample.<br/><br/>
2.	Once you&#8217;ve created your new Flex project, you need to drop the Degrafa SWC you just downloaded into the libs folder. <br/><br/>
3.	For the sake of keeping things clean in your MXML you can add a Degrafa XML namespace in the root MXML tag where you&#8217;ll be using Degrafa. For example, adding the Degrafa namespace in the Application tag of DegrafaExample.mxml could look like this:<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application     
      xmlns:mx="http://www.adobe.com/2006/mxml" 
      xmlns:Degrafa="http://www.degrafa.com/2007"     
      layout="absolute">      
</mx:Application>
</mt:CodeBeautify>
</div></div>
<br/>
The Basics of Composition By following those steps you can now access any of the Degrafa MXML tags for creating your graphics. Before you do though, there are a few fundamentals you&#8217;ll want to keep in mind when composing graphics. The following steps expose some of these fundamentals and walks through the basics of creating graphics with Degrafa resulting in a final composition of a single white Circle shown in Figure 1 and <a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaExample/DegrafaExample.html" target="_blank">viewable here</a>.<br/>
<br/>

<div  align="center" width="180"><img src="http://www.insideria.com/upload/2008/04/an_introduction_to_degrafa/deg1.png" alt="deg1.png"/></div>
<div align="center" width="180">Figure 1 - Basic Circle</div>
<br/>
1.	Graphic objects defined with Degrafa are drawn by a series of commands that require an object to be rendered upon. To define this you can either use a Degrafa <strong>GeometryGroup</strong> tag within a <strong>Surface</strong> tag, like this: <br/>
<br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:Surface>     
    <Degrafa:GeometryGroup>         
    <!-- Add Degrafa Shapes Here -->     
    </Degrafa:GeometryGroup> 
</Degrafa:Surface>
</mt:CodeBeautify>
</div></div> 

The Degrafa Surface tag is a UIComponent, which means you can set properties like verticalCenter, horizontalCenter, etc. and the GeometryGroup tag is a Sprite, which has fewer properties than UIComponent.<br/>
<br/>
2.	The other option you have for specifying an area to draw Degrafa graphics to is to use the <strong>graphicsTarget</strong> property with a <strong>GeometryComposition</strong> or other geometry tag like Circle, RegularRectangle, etc. This will allow you to define graphic objects outside of the component and target any graphics context, i.e., any component that accepts graphics, like a Canvas, Button, Image, etc. <strong>This will be the method used in this basic example</strong>.<br/>
<br/>
3.	Add a <strong>Canvas</strong> in the application MXML and give it an id of myCanvas. Also, add a <strong>GeometryComposition</strong> and specify myCanvas in the graphicsTarget property like this:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:GeometryComposition     
    graphicsTarget="{[ myCanvas ]}">     
    <!-- Add Degrafa Shapes Here --> 
</Degrafa:GeometryComposition>     
<mx:Canvas    
    id="myCanvas"/> 
</mt:CodeBeautify>
</div></div> 
4.	Once you&#8217;ve specified the graphics context you want to draw to you can start drawing Degrafa geometry. There are a number of pre-created Degrafa geometry objects that you can use to create your compositions, like Circle, RegularRectangle, Path, LineRepeater, and more. These objects can be drawn within a GeometryGroup, GeometryComposition, or by themselves using the graphicsTarget property. For this example, add a <strong>Circle</strong> within the GeometryComposition:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:GeometryComposition     
    graphicsTarget="{[ myCanvas ]}">     
    <Degrafa:Circle         
        radius="100"         
        centerX="120"         
        centerY="120"/> 
</Degrafa:GeometryComposition>      
<mx:Canvas     
    id="myCanvas"/>
</mt:CodeBeautify>
</div></div> 
5.	That last bit of MXML draws a Circle, but you can&#8217;t see it because it needs to have a fill or stroke applied to it. Degrafa comes with a number of fill and stroke capabilities that are sure to meet the majority of your needs. There are Solid, Linear Gradient, Radial Gradient, Blend, and Complex Fills. Stroke types include Solid, Linear Gradient, and Radial Gradient options. To get the Circle in this example to show up you can apply a <strong>SolidFill</strong> within the Circle like this:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:GeometryComposition     
    graphicsTarget="{[ myCanvas ]}">     
    <Degrafa:Circle         
        radius="100"         
        centerX="120"         
        centerY="120" >         
        <Degrafa:fill>             
            <Degrafa:SolidFill                 
                color="#FFF"/>         
        </Degrafa:fill>     
    </Degrafa:Circle> 
</Degrafa:GeometryComposition>      
<mx:Canvas     
    id="myCanvas"/>
</mt:CodeBeautify>
</div></div> 
<strong>Note</strong>: With the binding features of Degrafa you can also specify Fills and Strokes outside of geometry and assign the fill or stroke by referencing its id. This is a great way to repurpose fills and strokes across geometry objects. The following MXML snippet shows the same fill used above, but pulled outside of the Circle tag and assigned using the fill&#8217;s id of myFill:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:fills>     
    <Degrafa:SolidFill         
        id="myFill"         
        color="#FFF"/> 
</Degrafa:fill>

<Degrafa:Circle     
    radius="100"     
    centerX="120"     
    centerY="120"     
    fill="{myFill}"/>

</mt:CodeBeautify>
</div></div> 
<a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaExample/DegrafaExample.html" target="_blank">
View the final product</a> or <a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaExample/srcview/index.html" target="_blank">view the source</a>.<br/>
<br/>
<strong>Thoughts on Binding</strong><br/>
One of the features I use the most in Degrafa is binding. Binding means creating a relationship between two properties such that when one updates the other is dynamically updated. This can be a very powerful feature when you think about binding properties like width, height, radius, fill, stroke, etc. between geometry objects to create some very dynamic relationships for a variety of purposes.<br/>
<br/>
A simple example would be binding the angle of a LinearGradientFill to a HorizontalSlider so that the angle of the gradient would change dynamically based on the updated value of the slider (don&#8217;t forget to set live dragging on the slider). A more complex example would be a list of items whose backgrounds change based on dynamic data.<br/>
<br/>
When you start to think of all the data you could use to influence graphics drawn with Degrafa it seems the possibilities are endless; interfaces that change based on cursor coordinates, buttons that change at different stages in a process, icons that change based on time of day, and charts that change shape based on new data. All it takes is a little experimentation with your own data sets, various public APIs, and user input. With binding in Degrafa you&#8217;ll start to see opportunities to create dynamic graphics in Flex.<br/>
<br/>
<strong>A More Advanced Implementation </strong><br/>
<br/>
Now that we&#8217;ve covered some of the capabilities of Degrafa and the basics of composing graphics, let&#8217;s take a look at more involved example. The following steps will walk through creating a Flex Clock (Figure 2) to illustrate some of the features of Degrafa mentioned throughout this article and create a more advanced graphics composition. You can see the final product <a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaFlexClock/FlexClock.html" target="_blank">here</a>.<br/>
<br/>
<div  align="center" width="180"><img src="http://www.insideria.com/upload/2008/04/an_introduction_to_degrafa/deg2.png" alt="deg2.png"/></div>
<div align="center" width="180">Figure 1 - Flex Clock</div>
<br/>
1.	To get started, create a new Flex application within your <strong>DegrafaExample</strong> folder and name it <strong>FlexClock.mxml</strong>. For convenience, add the same XML namespace mentioned in the previous example to your Application tag:<br/>
<br/>
xmlns:Degrafa="http://www.degrafa.com/2007"<br/>
<br/>
2.	For this example, you&#8217;ll be composing the different parts of the Flex Clock as <strong>GeometryGroups</strong> to take advantage of some of the properties of Sprite, like rotation for the clock hands.<br/>
<br/>
The first thing you need to do is set up the <strong>Surface</strong> tag so you can start adding the parts of the clock as <strong>GeometryGroups</strong>. Set the <strong>x</strong> and <strong>y</strong> of the Surface to <strong>100</strong> to position the clock within your application.<br/>
<br/>
3.	Add a GeometryGroup tag within the Surface tag and give it an id of <strong>clockFace</strong>. Within this <strong>GeometryGroup</strong> you&#8217;ll create the face of the clock, which is made up of the dark gradient background and letters &#8220;Fx&#8221;.<br/>
<br/>
To create the <strong>dark grey face</strong> of the clock you can use a <strong>RegularRectangle</strong> object inside the clockFace GeometryGroup. Set the <strong>height</strong> and <strong>width</strong> of the RegularRectangle to <strong>360</strong>. You also need to create that dark grey radial gradient fill for the RegularRectangle, but at this point the clockFace MXML should look like this: <br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:GeometryGroup     
    id="clockFace">     
    <Degrafa:RegularRectangle         
        width="300"         
        height="300"/> 
</Degrafa:GeometryGroup> 
</mt:CodeBeautify>
</div></div> 
<br/>
4.	Outside the clockFace GeometryGroup, create a new <strong>fills</strong> tag. Within that fills tag, add a <strong>RadialGradientFill</strong> tag and set the <strong>cx</strong> property to <strong>40</strong>, <strong>cy</strong> to <strong>20</strong>, radius to <strong>440</strong> and give it an id of <strong>greyRadFill</strong>. The last thing you need to do to finish this fill is assign gradient stops within the fill.<br/>  
<br/>
Gradient stops are the attributes that make up a gradient and have their own set of properties, including color, alpha, and ratio. In Degrafa, you use a <strong>GradientStop</strong> tag to create a gradient stop within a radial or linear gradient fill. You can set as many gradient stops as you need to get the desired effect you&#8217;re looking for. For the purposes of this example, just create<strong> two gradient stops</strong>. Give the first gradient stop a color of <strong>#444</strong> and the second a color of <strong>#000</strong>.<br/>
<br/>
<strong>Note:</strong> You may have noticed that the colors for the gradient stops were defined using three digits rather than the six that Flex normally requires. This is similar to what is doable in HTML and another feature of Degrafa. In fact, you have several options for specifying colors within the color property. You can specify a color with a HEX value (#666), RGB value (60,60,60), color key (grey), or CMYK (0,0,0,60). <br/>
<br/>
5.	Now that you&#8217;ve created the <strong>dark grey fill</strong>, it must be applied to the <strong>RegularRectangle</strong> you created earlier. As mentioned previously in this article, you can apply a fill to an object using the fill property. The MXML for the RegularRectangle and RadialGradientFill should look like this:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:fills>     
    <Degrafa:RadialGradientFill         
        id="greyRadFill"         
        cx="40"         
        cy="20"         
        radius="340">         
        <Degrafa:GradientStop            
            color="#444"/>         
        <Degrafa:GradientStop             
            color="#000"/>     
    </Degrafa:RadialGradientFill> 
</Degrafa:fills>      
<Degrafa:GeometryGroup     
    id="clockFace">    
    <Degrafa:RegularRectangle         
        width="300"         
        height="300"         
        fill="{ greyRadFill }"/> 
</Degrafa:GeometryGroup> 
</mt:CodeBeautify>
</div></div> 
6.	If you <strong>run your application</strong> you should see the RegularRectangle you created filled with a dark grey radial gradient. There&#8217;s the base for the clock face. <br/>
<br/>
Now you can create the remainder of the fills and strokes up front for the other elements of the clock and apply them as you go. You need to create a <strong>solid white fill</strong> for the &#8220;Fx&#8221; letters, a <strong>10 pixel solid red stroke</strong> for the hour and minute hands, and a <strong>2 pixel light grey stroke</strong> for the second hand. The fills tag has already been specified, but you need to add a strokes tag as well. Adding these new fills and strokes to the <strong>greyGradFill</strong> you already created should look like this in your MXML: <br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<Degrafa:fills>     
    <Degrafa:RadialGradientFill         
        id="greyRadFill"         
        cx="40"         
        cy="20"         
        radius="340">         
    <Degrafa:GradientStop             
        color="#444"/>         
    <Degrafa:GradientStop             
        color="#000"/>     
    </Degrafa:RadialGradientFill>     
    <Degrafa:SolidFill        
         id="whiteFill"         
        color="#FFF"/> 
</Degrafa:fills>          
<Degrafa:strokes>     
    <Degrafa:SolidStroke         
        id="redStroke"         
        color="#C50"         
        weight="10"         
        caps="none"/>     
    <Degrafa:SolidStroke         
        id="greyStroke"         
        color="#666"         
        weight="2"         
        caps="none"/> 
</Degrafa:strokes> 
</mt:CodeBeautify>
</div></div> 
<br/>
<strong>Note</strong>: You could expose Fill and Stroke properties to a designer to allow for customization without having them get involved with code.  <br/>
<br/>
7.	With all the fills and strokes you&#8217;ll need for this example created, let&#8217;s add the remaining parts of the clock. You already have the dark grey background created, so now you need to finish the clock face and add the <strong>&#8220;Fx&#8221; letters</strong>. For these letters you will use a <strong>Polygon</strong> tag within the <strong>clockFace</strong> GeometryGroup.<br/>
<br/>
For the &#8220;F&#8221; create a Polygon tag within the clockFace and assign whiteFill to the fill property. A <strong>Polygon</strong> takes shape by specifying a series of points, so rather than completely ending the Polygon tag, close it and set a points tag within. To specify the individual points, use a <strong>GraphicPoint</strong> tag for each point and specify the x and y values for each point. Instead of making you figure out the points to define the &#8220;F&#8221; I&#8217;ve defined them in the MXML block below along with the MXML for the &#8220;x&#8221;:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px; height: 240px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript"> 
<!-- The White "F" Polygon --> 
<Degrafa:Polygon     
    x="74"     
    y="90"     
    fill="{ whiteFill }">     
<Degrafa:points>        
    <Degrafa:GraphicPoint             
        x="1.716"            
        y=".868"/>         
    <Degrafa:GraphicPoint             
        x="91.638"             
        y=".868"/>         
    <Degrafa:GraphicPoint             
        x="92.329"             
        y="21.965"/>         
    <Degrafa:GraphicPoint             
        x="30.768"             
        y="21.965"/>         
    <Degrafa:GraphicPoint             
        x="30.768"             
        y="71.768"/>         
    <Degrafa:GraphicPoint             
        x="85.758"             
        y="71.768"/>         
    <Degrafa:GraphicPoint             
        x="85.758"             
        y="95.632"/>         
    <Degrafa:GraphicPoint             
        x="30.768"             
        y="95.632"/>         
    <Degrafa:GraphicPoint             
        x="30.768"             
        y="164.11"/>         
    <Degrafa:GraphicPoint             
        x="1.37"             
        y="164.11"/>     
    </Degrafa:points> 
</Degrafa:Polygon> 
<!-- The White "x" Polygon --> 
<Degrafa:Polygon     
    x="178"     
    y="140"     
    fill="{ whiteFill }">     
    <Degrafa:points>         
    <Degrafa:GraphicPoint             
        x="1.107"             
        y=".147"/>         
    <Degrafa:GraphicPoint             
        x="32.926"             
        y=".147"/>         
    <Degrafa:GraphicPoint             
        x="54.022"             
        y="39.574"/>         
    <Degrafa:GraphicPoint             
        x="76.503"            
        y=".147"/>         
    <Degrafa:GraphicPoint             
        x="105.209"             
        y=".147"/>         
    <Degrafa:GraphicPoint            
        x="72.354"             
        y="54.446"/>         
    <Degrafa:GraphicPoint             
        x="108.322"             
        y="113.932"/>         
    <Degrafa:GraphicPoint             
        x="73.736"             
        y="113.932"/>         
    <Degrafa:GraphicPoint             
        x="52.256"             
        y="73.43"/>         
    <Degrafa:GraphicPoint             
        x="32.505"             
        y="113.241"/>         
    <Degrafa:GraphicPoint            
        x=".07"             
        y="113.241"/>         
    <Degrafa:GraphicPoint             
        x="34.31"             
        y="58.596"/>         
    </Degrafa:points> 
</Degrafa:Polygon> 
</mt:CodeBeautify>
</div></div> 
<br/>
<strong>Note</strong>: So, how did I get those points? I actually traced the &#8220;Fx&#8221; in Adobe Illustrator, saved that as an SVG, opened that SVG in TextEdit, and within the definition of the SVG there is a <polygon> tag that had all the points I&#8217;m looking for. I just separated those points into the GraphicPoint tags for the Degrafa Polygon. <br/>
<br/> 
<strong>Note</strong>: For more information and clarification on how you can use SVG data in Degrafa, you can view this <a href="http://www.brightcove.tv/title.jsp?title=1130068155&channel=1130055106" target="_blank">screencast</a>.<br/>
<br/> 
8.	The only objects you have left to create are the <strong>clock hands</strong> for the hours, minutes and seconds. Each of these hands will be a <strong>HorizontalLine</strong> within their own <strong>GeometryGroup</strong>, so they can be rotated. Start with the <strong>second hand</strong> and apply the <strong>greyStroke</strong>: <br/> 
<br/> 
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<!-- The Second Hand --> 
<Degrafa:GeometryGroup     
    id="secondHand"     
    x="180"     
    y="180">     
    <Degrafa:HorizontalLine         
        x="0"         
        x1="160"         
        y="0"         
        stroke="{ greyStroke }"/> 
</Degrafa:GeometryGroup> 
</mt:CodeBeautify>
</div></div> 
<br/>
9.	Below the second hand, create the <strong>minute</strong> and <strong>hour hands</strong> the same way the second hand was created, but change the stroke to <strong>redStroke</strong> as well as the y1 values to make the hands <strong>shorter</strong> heights:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<!-- The Minute Hand --> 
<Degrafa:GeometryGroup     
    id="minuteHand"     
    x="180"     
    y="180">     
    <Degrafa:HorizontalLine         
        x="0"         
        x1="150"         
        y="0"         
        stroke="{ redStroke }"/> 
</Degrafa:GeometryGroup>  
<!-- The Hour Hand --> 
<Degrafa:GeometryGroup     
    id="hourHand"    
    x="180"     
    y="180">     
    <Degrafa:HorizontalLine         
        x="0"         
        x1="100"         
        y="0"         
        stroke="{ redStroke }"/> 
</Degrafa:GeometryGroup> 
</mt:CodeBeautify>
</div></div> 
<br/>
10.	If you now compile your application you should see the second, minute and hour hands in a horizontal orientation overlapping each other. You now have all the parts of your Flex Clock created, so now you can get it wired up and working.<br/>
<br/>
To save time I&#8217;ve put together the necessary code to get the <strong>clock ticking</strong>. You can use the following <strong>Script</strong> block and place it right below the <strong>Application</strong> tag:<br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">
<mx:Script>     
    <![CDATA[                                  
        private var clocktick:Timer= new Timer(1000);                      
        public function initTime():void        
        {                 
            setTime(new Date());             
            clocktick.addEventListener(TimerEvent.TIMER, initDraw);             
            clocktick.start();        
        }                      
        private function initDraw(event:TimerEvent):void         
        {             
            setTime(new Date());             
        }          
        public function setTime(currtime:Date):void          
        {             
            var currseconds:uint = currtime.getSeconds();             
            var currminutes:uint = currtime.getMinutes();             
            var currhours:uint = currtime.getHours();             
            secondHand.rotation = 268 + (currseconds * 6);             
            minuteHand.rotation = 268 + (currminutes * 6);                      
            hourHand.rotation = 268 + (currhours * 30) + (currminutes * 0.5);         
        }     
    ]]&gt;  
</mx:Script> 
</mt:CodeBeautify>
</div></div> 
<br/>
11.	With that added, the final thing you need to do to set the Flex Clock in motion is fire off the initTime() function on your Application&#8217;s creationComplete event:<br/>  
<br/>
creationComplete="initTime()"  
<br/>
Compile your app and check what time it is! You should see the time reflected by the rotation of the clock hands. The best thing is that the graphics are all done through MXML markup. You could easily go in and change the colors or type of strokes and fills, add some easing, bitmap filters. Leveraging the flexibility of working with Degrafa you could change the fill colors of the clock face based on time of day, or create an animation that shakes the clock like an alarm. There are a ton of possibilities and it&#8217;s easy!<br/>  
<br/>
View the <a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaFlexClock/FlexClock.html" target="_blank">final product</a> or <a href="http://samples.degrafa.com/DegrafaInsideRIA/DegrafaFlexClock/srcview/index.html" target="_blank">view the source</a>. 
<br/>
<br/>
<strong>Degrafa vs. ActionScript</strong><br/>
As a developer you may be asking, why wouldn't I just do all my drawing in ActionScript rather than Degrafa MXML? Well, there's nothing that Degrafa does that you couldn't do in ActionScript. The amount of code needed to do something like a simple Circle in ActionScript is no more involved than using Degrafa MXML, however, in more complex scenarios you may find executing using ActionScript to be overwhelming.<br/>
<br/>
Another reason is that the nature of the code is related to graphics and layout. You'll find it to be a more intuitive way to compose graphics through MXML markup rather than programmatically. With Degrafa, there is a more apparent visual structure to follow for laying out your geometry elements and their relationships via the nesting that occurs in MXML, while ActionScript is a lot more abstract and harder to follow, especially when using procedural methods to draw your objects.<br/>
<br/>
There are a lot of things that are done for you in Degrafa so that you don't need to worry about advanced math or coordinates. It's really about being more productive and being able to leverage the power of programmatic drawing to create flexible and dynamic visuals without making your brain hurt.<br/>
<br/>
<strong>Final Thoughts</strong><br/>
These two examples just scratch the surface of what is possible with Degrafa. There are a number of things that couldn&#8217;t be covered in this article given the length, but I encourage you to check out some of the provided resources at the end of this article to learn about more of the features of Degrafa.<br/>
<br/>
The features that Degrafa has like binding, advanced CSS, the ability to use SVG path data, utilities, focus on code reuse and more, enables you to quickly iterate on real applications at a pace that is more in line with client demands. As always, not every solution is the right one for everybody, but this framework was built by developers and designers to be one that they would use on a day to day basis to meet some of the most stringent needs. You can learn more about Degrafa at the following links: <br/>
<br/>
<br/>
<strong>Website and Blog</strong>: <a href="http://www.degrafa.com" target="_blank">http://www.degrafa.com</a><br/> 
<strong>Documentation</strong>: <a href="http://docs.degrafa.com" target="_blank">http://docs.degrafa.com</a><br/>
<strong>Samples</strong>: <a href="http://samples.degrafa.com" target="_blank">http://samples.degrafa.com</a><br/>
<strong>Code Source and Repository</strong>: <a href="http://code.degrafa.com">http://code.degrafa.com</a><br/>
<strong>Discussion</strong>: <a href="http://group.degrafa.com" target="_blank">http://group.degrafa.com</a><br/>
<strong>Community Showcase</strong>: <a href="http://showcase.degrafa.com" target="_blank">http://showcase.degrafa.com</a><br/>]]></description>
            <link>http://www.insideria.com/2008/05/an-introduction-to-degrafa-1.html</link>
            <guid>http://www.insideria.com/2008/05/an-introduction-to-degrafa-1.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">features</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">degrafa</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">flex</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">graphics</category>
            
            <pubDate>Mon, 05 May 2008 11:00:00 -0800</pubDate>
        </item>
        
        <item>
            <title>Anatomy of an Enterprise Flex RIA Part 16: The Models</title>
            <description><![CDATA[<div class="ap_r" style="margin: 16px;"><a href="http://www.insideria.com/upload/2008/05/anatomy_of_an_enterprise_flex/riaseries_part16.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/anatomy_of_an_enterprise_flex/riaseries_part16.jpg" alt="riaseries_part16.jpg" title="Click to enlarge" width="148"/></a></div>

<p>There are also two models, BookieModel and AdminModel. Models are just buckets for data. Models may become more complex and expose a set of methods as an API to act on the data they hold. Figure 20 shows the two models in Bookie.</p>
 

<p>The role of a model in a Cairngorm application is to hold data that drives the view. The controllers of the application, which are commands accessed through a FrontController, do what they need to do to get data in a form ready for the model, which may include accessing a service, then change the data on the model. The view is generally "bound" to the model's data and updates automatically through Flex's excellent binding mechanism. Again, we'll see how the view works in the next iteration.</p>

<div class="ap_c"><a href="http://www.insideria.com/upload/2008/05/anatomy_of_an_enterprise_flex/series16_figure20.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/anatomy_of_an_enterprise_flex/series16_figure20.jpg" alt="series16_figure20.jpg" title="Click to enlarge" width="400"/></a>
<div class="apcaption">Figure 20. The two models in Bookie</div>
</div>


<p>Models are generally simple beasts. Let's look at the BookieModel:</p>

<div class="acode" style="overflow: auto; padding: 10px; height: 40px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">package lcds.examples.bookie.model
{
...
    [Bindable]
    public class BookieModel implements ModelLocator {
</mt:CodeBeautify>
</div></div> 
    
<p>This model implements ModelLocator, which is simply a marker interface, meaning that it doesn't specify any methods to implement; it just marks the class as being of a certain type. Notice that the class is annotated with the [Bindable] metadata tag, just like our ActionScript DTOs. This means any public properties on the model are available for use in Flex's binding framework.</p>

<div class="acode" style="overflow: auto; padding: 10px; height: 90px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">...
private static var instance:BookieModel;

//States
public static const SIGNED_OUT:String    = 'SIGNED_OUT';
public static const SIGNED_IN:String     = 'SIGNED_IN';
public static const BOOKS_CHOSEN:String  = 'BOOKS_CHOSEN';

public var currentState:String = SIGNED_OUT;

public var books:ArrayCollection = new ArrayCollection();
public var authors:ArrayCollection = new ArrayCollection();
public var subjects:ArrayCollection = new ArrayCollection();
public var booksToReserve:ArrayCollection = new ArrayCollection();
public var user:Person;
public var loginFailedMessage:String = "";
...</mt:CodeBeautify>
</div></div> 

<p>Under the "States" comment are three constants which hold unique strings that we'll use to control the state of the Application view, index.mxml. At any point, currentState can be set to any one of these constants' values, and later we'll see how the application uses those constants to define states.</p>

<div class="ap_r" style="width:180px;"><a href="http://www.oreilly.com/catalog/9780596514402/?CMP=ILC-dm_nav_related-books" target="_blank"><img border="0" src="http://www.oreilly.com/catalog/covers/9780596514402_cat.gif" width="180" height="233" /></a>
<div class="apcaption"><a href="http://www.oreilly.com/catalog/9780596514402/?CMP=ILC-dm_nav_related-books" target="_blank">Get your copy of Tony Hillerson's Enterprise Application Development with Flex.</a></div></div> 

<p>Next are all the public properties that will drive the view. We'll keep a list of all the books, authors, subjects, and books to reserve on the model, as well as a reference to the person logged in. The loginFailedMessage is there to be bound to the view and set with a command in case the login process fails.</p>

<p>That first private variable is a static instance of a BookieModel, which should tip you off that we're going to use the singleton pattern here. Models need to be singletons, so we need to make sure there's only one instance of the object in the application. This is important, because the model represents the state of the client, and that can't be done well if there isn't a definitive, single version of that state. Here are the rest of the methods necessary to implement the singleton pattern:</p>

<div class="acode" style="overflow: auto; padding: 10px; height: 90px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">...
         public static function getInstance():BookieModel {
              if (instance == null) instance = 
                   new BookieModel(new ModelInitializer());
              return instance;
         }
  
         public function BookieModel(initializer:ModelInitializer) {
         }
...
    }
}
class ModelInitializer {}</mt:CodeBeautify>
</div></div> 

<p>First there's a static accessor method that returns the single instance, and creates it if it's not already there. Now, in Java or other languages where you can make a constructor private, you'd do that to complete the singleton pattern, to make sure that only the class could instantiate an instance of itself. ActionScript doesn't allow private constructors, so we instead use a little hack. Inside the class, at the bottom after the end of the package block, we define another class called ModelInitializer, which is visible only to the model class because it's outside the package, but in the same file. That way, we can make sure, again, that only the model class can instantiate itself.</p>


<div class="acode" style="overflow: auto; padding: 10px; height: 90px;" ><div style="overflow-x: visible;">
<mt:CodeBeautify language="actionscript">...
public function initialize():void {
    books = new ArrayCollection();
    authors = new ArrayCollection();
    subjects = new ArrayCollection();
    booksToReserve = new ArrayCollection();
    user = null;
    loginFailedMessage = "";
}

public function getReservedTillDate(reservedOn:Date):Date {
    var millisecondsPerWeek:int = 1000 * 60 * 60 * 24 * 7;
    // reserve books for 2 weeks
    var reservedTill:Date = new Date(reservedOn.getTime() + (2*millisecondsPerWeek));
    return reservedTill;
}
...</mt:CodeBeautify>
</div></div> 

<p>Next there are a few helper methods: one to initialize the model, which means to clear out any data that it was holding, and another to calculate a date two weeks in the future to use as a "reserved until" date for when we make reservations.</p>

<p>Next time we're going to see how we can unit test Flex with Flex Unit. You can always find the entire series <a href="http://www.insideria.com/series-anatomy-flex.html">here</a>.</p>]]></description>
            <link>http://www.insideria.com/2008/05/anatomy-of-an-enterprise-flex.html</link>
            <guid>http://www.insideria.com/2008/05/anatomy-of-an-enterprise-flex.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">features</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">cairngorm</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">flex</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">livecycle data services</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">model locator design pattern</category>
            
            <pubDate>Mon, 05 May 2008 07:58:13 -0800</pubDate>
        </item>
        
        <item>
            <title>LFFS - 9: MXML Continued... And A Sample Application For You To Work With!</title>
            <description><![CDATA[<span class="mt-enclosure mt-enclosure-image"><img alt="Thumbnail image for flex-icon.png" src="http://www.insideria.com/assets_c/2008/02/flex-icon-thumb-200x200.png" width="200" height="200" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;"/></span>

<p>In our last installment, we briefly introduced the MXML language. We learned that all MXML tags are used as a sort of "short hand" representation of ActionScript code in Flex applications. This time, we continue to look at MXML and it's role as a helpful tool within the Flex programming environment.</p>

<p>All of the material in this article involving code, and indeed all code examples so far in the series, have been written using Flex Builder 3.0. It's worth noting that although we haven't yet devoted an entire installment to the use of Flex Builder, (we will very soon), those new to Flex and wishing to learn more should definitely head straight to the <a href="http://www.adobe.com/downloads/?ogn=EN_US-gntray_dl_trialdownloads">Adobe product downloads page</a> and grab their <a href="https://www.adobe.com/cfusion/tdrc/index.cfm?product=flex">free 60 day trial</a>. Flex Builder is as good as it gets as far as I. D. E.'s are concerned, and a great way to learn programming is to start messing around with code to try to get things to happen. On that note, we've included a sample application for you to experiment with, but more on that later.</p>

<p>We already know that MXML refers to ActionScript code, but in what way does it do that? To better understand this concept, it helps to know a little about the kinds of situations in which you'd use MXML in Flex. In other words; what types of MXML "documents" you are likely to create.</p>

<p>The most common types of MXML documents that can be created for use in Flex applications are application documents and component documents. Every Flex application that uses MXML requires an application document, but not necessarily a special component document, as we'll soon see.</p>

<p>Component documents are handy though, as they can used for creating customized components as simple as a Button control, or for more complex tasks, like dividing an application into <em><strong>modules</strong></em>, which can go a long way into ensuring that an application will run quickly. The included sample application makes use of a component document to define a custom Button component. An important concept to grasp is that both application and component documents are extensions of classes and are in fact classes themselves.</p>

<p>Application and component documents have root tags that are named after their base classes.  In the case of application documents, the root tag always extends the Application class. Component documents, on the other hand, have root tags named after whatever class the given component extends.</p>

<p>When you create a new project in Flex Builder, the code automatically generated is an application document, and it looks like this:</p>

 

<strong><p>&lt;?xml version="1.0" encoding="utf-8"?&gt;</p>
<p>&lt;mx:Application</p><p> xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"&gt;</p>

<p>&lt;/mx:Application&gt;</p>
</strong>
 

<p>Among other things, this code defines the application. The first line is what's known as an XML declaration. Technically, you can code an MXML or XML document without including this, but it's considered a best practice to include it, (and Flex Builder does this automatically for you). The declaration simply tells the parsers what version of XML encoding, as defined by the W3C, you're using.</p>

<p>The next line is the starting tag of the application. In addition to marking the beginning of the application, because it is the root tag, the default <em><strong>namespace</strong></em> for the document's classes is defined here as well. Earlier in the series, when we were discussing package declarations, we mentioned the importance of declaring them within a unique namespace in order to distinguish them from similarly named packages. Just like if you are in the room with more than one person named "Tom", for example, you'd address the person you wish to actually talk to by saying something more specific than "hey Tom"! The same goes for referencing objects within an application. So therefore, the code that reads:</p>

 
<strong>
<p>&lt;mx:Application </p><p>xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"&gt;</p></strong>

 

<p>can be translated into English as: "Within this instance of the Application class, the XML namespace uses a tag called "mx", and has as a part of its identity, the phrase - <strong>'http://www.adobe.com/2006/mxml</strong>', which is a unique name that is unlikely to be a part of any other namespace". The <strong>"layout='absolute'"</strong> declaration is what defines how the child objects of the application are to be laid out, meaning that their location depends upon a specific "x/y" coordinate. Other possibilities include <strong>"layout='horizontal'"</strong>, which lays out child objects horizontally, and <strong>"layout='vertical'"</strong>, which lays the child objects in a vertical orientation.</p>

<p>The point about the application tag referring to an instance of the Application class is an important one to understand in order to see how MXML tags work within an application. Remembering that tags refer to a class's objects will help to make sense of what we are looking at when we see MXML code.</p>

<p>The information that follows <strong>(&lt;mx:Application)</strong>, and comes before the <strong>(&gt;)</strong> on that line are known as tag <strong><em>attributes</em></strong>. As we'll soon see, an MXML tag can hold information in attributes, as in the above example, or in<strong><em> content</em></strong> tags. A tag's attributes are anything that comes before the end of the opening tag, and a content tag is the code that is placed in its own separate tag, and then placed between the opening and closing tags. <em><strong>(&lt;opening tag&gt; &lt;content&gt; &lt;/content&gt; &lt;/closing tag&gt;)</strong></em> In most cases, the results are the same if you use attributes, or if you embed the content in nested tags. Consider that the following code:</p>

 

<strong><p>&lt;mx:Button label = "magic" /&gt;</p></strong>

 

<p> means the same as this code:</p>

 
<strong>
   <p>  &lt;mx:Button&gt;</p>

   <p>&lt;mx:label&gt; "magic" &lt;/mx:label&gt;</p>

<p>&lt;/mx:Button&gt;</p>
</strong>

 

<p>Both of these examples refer to an instance of the Button class' properties (label), they just do it differently. In the first example, the property is listed <em><strong>inline</strong></em>, whereas in the second, it is <em><strong>nested</strong></em>. The choice to code your MXML in the form of attributes or within nested tags may have to do with the complexity of the properties and methods you need to access within the tagged object. For example, I may do this:</p>

 
<strong>
<p>&lt;mx:Button label = "HI" /&gt;</p>
</strong>
 

<p>But, if things got a bit more complex, I might do this::</P

 
><strong>
<p>&lt;mx:VBox&gt;</p>
<p>&lt;mx:Button label="my button 1" /&gt;</p>
<p>&lt;mx:Button label="my button 2" /&gt;</p>
<p>&lt;mx:Button label="my button 3" /&gt;</p>
<p>&lt;/mx:VBox&gt;</p>
</strong>
 

<p>So, in a sense, just as MXML makes bringing ActionScript into your application much easier, having a choice between using tag attributes and using nested tags can also make things go smoother.</p>

<p>An important part of most application documents is completely ignored by the parser . We've discussed "comments" before as they apply to ActionScript, and just like other markup languages, MXML has them too. By typing <em><strong>(<!--your comment goes here -->)</strong></em>, just as in HTML and XML, the content within those tags will be ignored by the parser.</p>

<p>Another important tag to be familiar with is the &lt;mx:Script&gt; tag which is followed up by what's known as the "CDATA" section. When you see something like this:</p>

 
<strong>
<p>&lt;mx:Script&gt;</p>
<p>&lt![CDATA[</p>

<p>]]&gt;</p>
<p>&lt;/mx:Script&gt;</p>
</strong>
 

<p>what you are seeing is a place where you can put ActionScript code into your MXML application. The script tag let's the MXML parser not to treat it's contents as markup code. Content within the CDATA tags is interpreted by the ActionScript compiler instead.</p>

<p>Hopefully we've covered enough ground since the beginning of the series so those that are new to Flex can start to make sense of an actual application when viewing the source code. As mentioned earlier, we've included an example application in this post for you to work with. It's a calculator that doesn't work yet; it needs to have the logic programmed into it! It looks nice, and a few of the buttons do stuff to get you started, but you'll need to figure out how to use ActionScript and MXML to get it working properly. This is a great way for beginning programmers to gain an understanding of Flex beyond simply reading about it. To program this calculator you'll have to think about what it needs to do exactly, at every moment, and come up with a logical sequence of events. You should be able to get everything to work by manipulating some variables and functions in the event listener, but feel free to take any road you wish to make it work.</p>

 

<strong><p>A few tips:</p></strong>

 

<p>1- There is a custom component in this Flex project called "CalculatorButton", and it's in a small MXML document called "CalculatorButton.MXML". (note the correlations between the application document and the component document).</p>

 

<p>2- There are several "correct" ways to get this to work, and you can learn a lot from figuring out different versions of the same application.</p>

 

<p>3- I skipped the "M" buttons in my version because I never use them on real-world calculators anyway, although by all means, go nuts!</p>

 

<p>4- Once you can get it to add, subtract, whatever, you're close to being able to get it all to work!</p>

 

<p>5- You may have to create a sub-folder called "libs" in your project folder if Flex Builder doesn't create one for you, otherwise your program may not compile.</p>

 

<p>6- "Getting the calculator to work" implies actually getting it to do math correctly, not simply displaying something like "I'M A ROCKSTAR!" when you click any of the buttons, apparently.</p>

<p>7- Good luck!</p>
<p>&nbsp;</p>
<p><big><strong>The Sample Application</strong></big></p>

 <p>To get started with this example application using Flex Builder, click on the "download source" link and choose "save to disk".  Make a note of where the zip file gets stored.  Open up Flex Builder, and under "file" choose "import", and "Flex project".  Make sure "archive file" is selected on the next screen and browse to the zip folder that holds the application.  If everything is as it should be, you should be able to click on the "finish" button at the bottom.  You should see the Flex project appear in Flex Builder's navigator window.  Click on the project icon to expand the view into several folders.  Click on the src folder, and then click on Calculator.MXML.  This is the main application file.  Notice the other MXML file - CalculatorButton.MXML.  From here you can experiment with workspace views, namely "source mode", and "design mode".  Enjoy!</p>

 <p>In the next installment, I'll share the results of my attempt at making this calculator work.  We'll get into using Flex Builder as it applies to this project, and we'll set the course for more discussions on using the tools of Flex.</p>

 

 

 

<p>
  <iframe src="http://flexglossary.net/lffs/lffs-9-calculator/" width="400" height="350" style="border:none"></iframe>
  
</p>
<p><a href="http://flexglossary.net/lffs/lffs-9-calculator/srcview/" target="_blank">View Source</a> - <a href="http://flexglossary.net/lffs/lffs-9-calculator/srcview/Calculator.zip" target="_blank">Download Source</a></p>
<p>&nbsp;</p>
<p><big><big><strong>Glossary of Terms</strong></big></big></p>
<p><strong>XML</strong> - Extensible Markup Language. A markup language (or perhaps, pseudo-language), in which you create custom tags to define the way data is carried.</p>

 

<p><strong>MXML</strong>- An extensible markup language created by Adobe for use within the Flex framework. Much speculation surrounds the meaning of the "M", or perhaps "MX" in the name, as no official acronym has been announced.</p>
 

<p><strong>CDATA-</strong> The section of a document which the parser doesn't interpret as XML or MXML, so that a programmer may put ActionScript code code in.</p>

 
<p><strong>
application document-</strong> The main MXML document in a Flex application, that extends the Application class.</p>

 

<p><strong>component document-</strong> An MXML document that is used to create custom components.</p>

 
<p><strong>
module-</strong> A section of code within an application that is set apart to facilitate an applications run time efficiency.</p>

 

<p><strong>markup-</strong> elements of language that are used to determine the layout of data.</p>

 

<p><strong>tag-</strong> In markup languages, tags such as (&lt,/&gt) are used to define the beginning and end of important content.</p>

 
<p><strong>
attributes-</strong> In MXML, a tag represents an object, and attributes are the properties/methods of an object listed before the end of the opening tag.</p>

 

<p><strong>nested tags (content)-</strong> In MXML, a tag represents an object, and nested tags refer to the properties/methods that are listed between the opening and closing tags of the object.</p>

 
<p><strong>
XML declaration-</strong> A technically unnecessary, albeit proper declaration to include in an XML document that announces the particular encoding that will be used as set by the W3C.</p>


<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-3756476-19";
urchinTracker();
</script>]]></description>
            <link>http://www.insideria.com/2008/05/lffs-9-mxml-continued-and-a-sa.html</link>
            <guid>http://www.insideria.com/2008/05/lffs-9-mxml-continued-and-a-sa.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
            
            <pubDate>Fri, 02 May 2008 06:00:00 -0800</pubDate>
        </item>
        
        <item>
            <title>Adobe launches &quot;Open Screen&quot;, opens SWF and FLV formats</title>
            <description><![CDATA[Announced on <a href="http://blog.digitalbackcountry.com/?p=1404">Ryan Stewart's blog</a> and the <a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200804/050108AdobeOSP.html">Adobe Pressroom</a> this morning is Adobe <a href="http://www.adobe.com/openscreenproject/">Open Screen</a>: an initiative that involves not only releasing the SWF, FLV and FLV4 file format specifications, but also removes licensing restrictions around the next version of the AIR and Flash player.

The initiative's focus is on providing consistent experiences across all of the many platforms Flash content plays on, and expanding the number of flash-enabled platforms that exist.  To help in this, Adobe has partnered with a plethora of big companies whose roster reads like a "who's who" of the gadget world (Intel, Motorola, LG, Nokia, Toshiba, Samsung, Sony Ericson, MTV, NBC etc.)

With Open Screen Adobe is also launching an open source porting project to port the Flash player to new devices.  This is particularly exciting in the mobile space, where certain carriers haven't wanted to put the Flash Lite Player on their devices despite popular demand from the community.  That's right, iPhone - you're on notice.

Open Screen doesn't actually make SWF or FLV open source - it just makes the file format specifications open, and launches a community-driven porting initiative.  While many developers would probably like to see the player go completely open, it's going to be great to finally look inside and see what makes SWF tick.  Adobe has also always been pretty good about incorporating developer enhancements of their products, meaning if someone does find a good way to improve the SWF format, and I'm sure we will, Adobe will listen.

Adobe's decision comes at a timely moment when competition around plugin-based rich internet content is really heating up.  By going open source, Adobe hopes to rally the developer community around support for their format to compete with Microsoft, whose rich content formats are all still proprietary and, knowing Microsoft, will probably stay that way forever.

Open Screen is great news for us developers, especially those of us who struggle to squeeze every last bit of performance out of the SWF format.  I have some thoughts on where I'd like to see this go in the future (hint: it involves opening the Flash Player itself) but for now let's not dampen the mood with any of that criticism.  Hooray for the new Open-SWF!]]></description>
            <link>http://www.insideria.com/2008/05/adobe-launches-open-screen-ope.html</link>
            <guid>http://www.insideria.com/2008/05/adobe-launches-open-screen-ope.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">News &amp; Events</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">adobe</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">open source</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">swf</category>
            
            <pubDate>Thu, 01 May 2008 06:51:14 -0800</pubDate>
        </item>
        
        <item>
            <title>Cuzillion - Optimizing Web App Assets and Scripts</title>
            <description><![CDATA[Steve Souders the creator of <a href="http://developer.yahoo.com/yslow/">YSlow</a> has now released <a href="http://stevesouders.com/cuzillion/">Cuzillion</a> which is essentially a page load simulation tool.  Very cool for figuring the best way to structure your and in which order to load assets.

<blockquote>Cuzillion is a tool for quickly constructing web pages to see how components interact. Browsers have unexpected behavior in everyday situations (for example, inline scripts block all rendering in the page and nothing can download in parallel with an external script). Sometimes the behavior differs across browsers (Internet Explorer 8 downloads six items in parallel whereas Firefox 2.0 only downloads two in parallel). Cuzillion lets you observe these behaviors and share sample pages with others</blockquote>. 

<a href="http://almaer.com/blog/">Dion</a> did a quick interview with him which contains a good explanation of how it works.
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/oaxZtKAlLRk&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/oaxZtKAlLRk&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>

As per the screencast Steve walks us through an example of how Cuzillion could be used:

<blockquote>A great example of how Cuzillion is useful is looking at the impact inline scripts have when they follow a stylesheet in Internet Explorer. Typically, a stylesheet followed by any other resource results in both resources being downloaded in parallel in Internet Explorer. (In Firefox stylesheets block parallel downloads, so this performance optimization is only applicable to IE.) Here&#8217;s a Cuzillion page that shows this: stylesheet and image downloading in parallel. Both the stylesheet and image are configured to take 2 seconds to download. Since they download in parallel the page takes about 2 seconds to load as shown by the &#8220;page load time&#8221;.

But look what happens if we put an innocent inline script between the stylesheet and image: stylesheet, inline script, and image. Now, in Internet Explorer the stylesheet and image are downloaded sequentially, which means the page load time goes from 2 seconds to 4 seconds. If the inline script is simply moved above the stylesheet the two resources are downloaded in parallel again, and the page load goes back down to 2 seconds: inline script, stylesheet, and image.</blockquote>

Read more about it on <a href="http://www.stevesouders.com/blog/2008/04/25/cuzillion/">Steve's blog</a>.

I think it's great tool for developers to optimize their application load times and also could be used as an educational tool for new developers as well.]]></description>
            <link>http://www.insideria.com/2008/04/cuzillion-optimizing-web-app-a.html</link>
            <guid>http://www.insideria.com/2008/04/cuzillion-optimizing-web-app-a.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Development</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">blogs</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">screencasts</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">ajax</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">cuzillion</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">performance</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">steveounders</category>
            
            <pubDate>Wed, 30 Apr 2008 13:48:41 -0800</pubDate>
        </item>
        
        <item>
            <title>Flex RIA Performance Considerations Part 2: Application Startup</title>
            <description><![CDATA[<div style="border-style: none none double; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 2.25pt; padding: 0in 0in 1pt;">
<p class="MsoNormal" style="border: medium none ; margin: 0in 0in 0pt; padding: 0in;"><b style=""><span style="font-family: 'Trebuchet MS','sans-serif';"><font size="3"><font color="#000000">Overview<o:p></o:p></font></font></span></b></p></div>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">As Flex developers we strive to create user experiences that are engaging and efficient.<span style="">&nbsp; </span>The mandate of this mantra requires us to take startup times into account.<span style="">&nbsp; </span>When we build our applications, the last thing that we need is for our users to get bored and frustrated before they even start using our applications.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p><o:p></o:p></p>
<p>
</p><form contenteditable="false" class="mt-enclosure mt-enclosure-image" mt:asset-id="1354"><a onclick="window.open('http://www.insideria.com/part2_preloader1.html','popup','width=194,height=75,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false" href="http://www.insideria.com/part2_preloader1.html"><img dragover="true" class="mt-image-left" style="margin: 0px 20px 20px 0px; float: left;" alt="part2_preloader.png" src="http://www.insideria.com/part2_preloader-thumb-194x75.png" height="75" width="194" /></a></form>
<form contenteditable="false" class="mt-enclosure mt-enclosure-image" mt:asset-id="1354">&nbsp;</form>
<p dragover="true" class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font dragover="true" face="Times New Roman">We&#8217;re all familiar with the DownloadProgressBar that shows up during preload.<span style="">&nbsp; </span>Let&#8217;s talk about how to make it go away faster and get users working with our applications in the shortest amount of time possible.<span dragover="true" style="">&nbsp; </span></font></font></font></p>
<p dragover="true" class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">When thinking about application startup optimization, there are a couple things to strive for:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"></font>&nbsp;</p>
<ol>
<li>
<div class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Minimizing download time</font></div></li>
<li>
<div class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Deferring instantiation</font></div></li></ol>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">That being said, let&#8217;s take a look at the techniques and things to watch out for.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<div style="border-style: none none double; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 2.25pt; padding: 0in 0in 1pt;">
<p class="MsoNormal" style="border: medium none ; margin: 0in 0in 0pt; padding: 0in;"><b style=""><span style="font-family: 'Trebuchet MS','sans-serif';"><font size="3"><font color="#000000">Minimizing Download Time<o:p></o:p></font></font></span></b></p></div>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><span style="font-family: 'Trebuchet MS','sans-serif';"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font face="Times New Roman">Download file sizes and Internet connection speeds can really affect the time it takes for a Flex application to start up.<span style="">&nbsp; </span>Unfortunately, those are two factors that we have hardly any control over.<span style="">&nbsp; </span>The good news is we have a couple of things that kind of help us in this realm, although they have some drawbacks.<span style="">&nbsp; </span></font></font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">First, there&#8217;s caching mechanisms in the modern web browser.<span style="">&nbsp; </span>In an ideal end user situation, their browser cache is turned on, so your files can be cached locally on their machine which saves time up front.<span style="">&nbsp; </span>The bad news is you really cannot rely on the fact that an end user&#8217;s browser will be pulling your files from the cache most of the time.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Second, the Flash Player was built to stream frames.<span style="">&nbsp; </span>In other words, the Flash Player can start your Flex application while it&#8217;s still downloading the application SWF.<span style="">&nbsp; </span>The bad news, is until enough of your application has loaded to show frame two, the only thing the end user will see is the Preloader screen.<span style="">&nbsp; </span>The reason being, in a standard Flex application there is only two frames.<span style="">&nbsp; </span>Frame one is where the SystemManager and the preload process lives, it is the frame that is running when you see the &#8220;Loading&#8221; display.<span style="">&nbsp; </span>The second frame is where your application lives.<span style="">&nbsp; </span>This is why minimizing what needs to occur before the preload process completes is crucial.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">So what is a developer to do to move on to frame two?</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><font size="3"><font color="#000000"><font face="Times New Roman">Beware the Embed<o:p></o:p></font></font></font></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">The Flex framework makes available to you a way to compile assets such as images, mp3 files and fonts directly into your application SWF.<span style="">&nbsp; </span>Although this comes in handy with making sure that the end user will have a copy of your assets this is a very good way of causing your application to remain in &#8220;Loading&#8221;.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">For example, take this application that contains an embedded mp3 file that&#8217;s just over 9MB.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_EmbeddedMp3/InsideRIA_EmbeddedMp3.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_EmbeddedMp3/InsideRIA_EmbeddedMp3.html</a></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font face="Times New Roman">If you notice, the application remains in the &#8220;Loading&#8221; state for a very long time.<span style="">&nbsp; </span>This is due to the fact that the application cannot move on to frame two until the 9MB or so of extra SWF has been downloaded.<span style="">&nbsp; </span>In the above case, keeping the file externalized and loading it in at runtime would have been a better option to decrease startup time.<span style="">&nbsp; </span></font></font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Although it may be highly unlikely that you&#8217;ll want to embed a 9MB file into your Flex app, imagine an app that has several embedded SVG images, or smaller mp3 files used as sound effects.<span style="">&nbsp; </span>Here&#8217;s another example, embedded fonts, which is very common.<span style="">&nbsp; </span>Let&#8217;s talk about fonts.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><font size="3"><font color="#000000"><font face="Times New Roman">Use Less Character<o:p></o:p></font></font></font></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">When you embed a font in Flex, you are given the whole range of characters supported by that font.<span style="">&nbsp; </span>Although that might be what you&#8217;re trying to accomplish with your application, are you sure you need all the characters?<span style="">&nbsp; </span>For instance, in an English-only applications are you sure you really need to spend time loading data for Chinese characters?</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here&#8217;s an example of an app that embeds two different font files with no character restrictions:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FontEmbed_NOT_Limited/InsideRIA_FontEmbed_NOT_Limited.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FontEmbed_NOT_Limited/InsideRIA_FontEmbed_NOT_Limited.html</a></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Now, here&#8217;s an example of the same application with a limited character set.<span style="">&nbsp; </span>In this case, the font is only being used in some labels that just display numerals, so the character set was limited to use just numbers and the period: </font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FontEmbed_Limited/InsideRIA_FontEmbed_Limited.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FontEmbed_Limited/InsideRIA_FontEmbed_Limited.html</a>&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"></font></o:p>&nbsp;</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">The thing to note here is if your browser cache is turned on, the difference between the two is negligible, however, if you delete the cached content between requests, you&#8217;ll see some serious startup time differences since the SWFs differ about 200KB in size.<span style="">&nbsp; </span>In my tests I was averaging about 500ms of savings by using the above technique.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Now that we know to limit the sizes of the files we&#8217;re serving up, how can we further decrease download requirements?</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><font size="3"><font color="#000000"><font face="Times New Roman">Caching the Framework <o:p></o:p></font></font></font></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">As of Flex 3 you can now cache Adobe signed framework RSLs into a Flash Player cache.<span style="">&nbsp; </span>The beauty of this is twofold.<span style="">&nbsp; </span>First, signed framework RSLs cached in the Flash Player cache are shared among all Flex applications that are configured to use them.<span style="">&nbsp; </span>In other words, if someone else&#8217;s app had already pulled down the 500KB or so of signed framework RSL, and the RSL is still in the Flash Player cache, your application can use that cached RSL.<span style="">&nbsp; </span>Second, if someone clears their browser cache, it does not affect the Flash Player cache.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">There are some caveats to Flash Player framework caching:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style=""><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></span></p>
<ul style="margin-top: 0in;" type="disc">
<li class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">The Flash Player must be version 9.0.115 or higher.</font></li></ul>
<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<ul style="margin-top: 0in;" type="disc">
<li class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Framework caching depends on a signed RSL.<span style="">&nbsp; </span>In general RSLs increase application startup time since the whole library in an RSL is loaded no matter what.<span style="">&nbsp; </span>In other words, even if you&#8217;re not using DataGrid and Tree, those classes are getting loaded.</font></li></ul>
<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<ul style="margin-top: 0in;" type="disc">
<li class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">If you are comfortable with relying on browser caching, then that&#8217;s usually going to be a faster startup time due to the nature of how RSL libraries are loaded as noted above.</font></li></ul>
<p class="MsoListParagraph" style="margin: 0in 0in 0pt 0.5in;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">So, here&#8217;s an application that uses no Framework caching:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_NOT_FrameworkCaching/InsideRIA_NOT_FrameworkCaching.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_NOT_FrameworkCaching/InsideRIA_NOT_FrameworkCaching.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here&#8217;s the same application using Framework caching:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FrameworkCaching/InsideRIA_FrameworkCaching.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_FrameworkCaching/InsideRIA_FrameworkCaching.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Overall, you benefit from Framework caching if the end user has browser caching turned off and/or their Internet connection speeds are slow.<span style="">&nbsp; </span>For instance, I had caching in the browser turned off and after the initial download of the signed Framework RSL I was consistently saving a good 400ms or so.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><b style=""><font size="3"><font color="#000000"><font face="Times New Roman">Use Modules<o:p></o:p></font></font></font></b></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Another way to minimize that up front load time is to break your Flex application into Modules.<span style="">&nbsp; </span>A benefit to using Modules is that you have control over when a Module is loaded into your application and also unloaded.<span style="">&nbsp; </span>In addition, you can optimize a module to work with your application, further decreasing the amount of data that needs to be downloaded by decreasing the size of the actual Modules SWF files.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here&#8217;s the same application from before, but now we&#8217;re using Modules and no Framework Caching:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_Modules_NON_OPTIMIZED/InsideRIA_Modules_NON_OPTIMIZED.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_Modules_NON_OPTIMIZED/InsideRIA_Modules_NON_OPTIMIZED.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Now here&#8217;s that same application using Modules, but in this case the Modules have been optimized for this specific application:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_Modules_OPTIMIZED/InsideRIA_Modules_OPTIMIZED.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_Modules_OPTIMIZED/InsideRIA_Modules_OPTIMIZED.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">If we keep caching turned off, the startup time gain I was getting by using Modules was about 500ms.<span style="">&nbsp; </span>Also, even though the optimized Step1.swf module is about 125KB smaller than the non-optimized one, there really didn&#8217;t seem to be any difference between the two when testing with my high-speed Internet connection.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Last point to make about Modules is the reason they were faster was because I could load them in just in time.<span style="">&nbsp; </span>In other words, the only Module loaded at startup was the Step1.swf Module.<span style="">&nbsp; </span>So in this case of Modules, the end-user saved on startup time, but will end up paying for it when they move from one Module to the next since each new Module will need to be loaded in a JIT manner.<span style="">&nbsp; </span>In the case of my app, this penalty is when the user moves through each of the steps 1-5 for the first time.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">So now that we&#8217;ve talked about how to improve our application startup time by decreasing the download requirements, let&#8217;s move on to how to improve startup time via our application logic.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<div style="border-style: none none double; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 2.25pt; padding: 0in 0in 1pt;">
<p class="MsoNormal" style="border: medium none ; margin: 0in 0in 0pt; padding: 0in;"><b style=""><span style="font-family: 'Trebuchet MS','sans-serif';"><font size="3"><font color="#000000">Deferring Instantiation<o:p></o:p></font></font></span></b></p></div>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font face="Times New Roman">The number one thing you can do to help minimize the amount of time from when data is downloaded to when the user can actually use the application is by deferring instantiation.<span style="">&nbsp; </span>The concept behind this technique is not creating objects in memory until they&#8217;re actually needed by the application.<span style="">&nbsp; </span></font></font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Although deferred instantiation techniques will cause little - and oftentimes unnoticeable - delays throughout the use of the application, this is often considered more acceptable behavior than having a long application startup delay.<span style="">&nbsp; </span>The other benefit to deferred instantiation is optimized memory utilization.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">When thinking about deferred instantiation, the number one thing to keep in mind is navigator containers such as ViewStack and TabNavigator.<span style="">&nbsp; </span>Sometimes developers are tempted to set their creationPolicy attribute to &#8220;all&#8221; so that they can access children without having a bunch of runtime exceptions caused by null values due to non-existent child components.<span style="">&nbsp; </span>The problem with this practice - other than increased memory utilization - is all the child components of the child containers in the navigator are created upfront, before the Preloader display is removed and before the application moves to frame two.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style=""><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here is an example of the app with creationPolicy=&#8221;all&#8221;:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_ALL/InsideRIA_CreationPolicy_ALL.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_ALL/InsideRIA_CreationPolicy_ALL.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font face="Times New Roman">The good news is that the creationPolicy in your navigation containers is not set to &#8220;all&#8221; by default.<span style="">&nbsp; </span>However, one thing you&#8217;ll notice, especially if the navigator children have many children or much associated data is that now when you go from one of the&nbsp;navigator child views&nbsp;to another, is that&nbsp;on first viewing you may see a slight delay as the children of that&nbsp;view&nbsp;are instantiated.<span style="">&nbsp; </span></font></font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here is an example of the app we&#8217;ve been working with creationPolicy=&#8221;auto&#8221;, the default:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_DEFERRED/InsideRIA_CreationPolicy_DEFERRED.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_DEFERRED/InsideRIA_CreationPolicy_DEFERRED.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="3"><font color="#000000"><font face="Times New Roman">That being said, there&#8217;s a way to have your cake and eat it too: ordered creation.<span style="">&nbsp; </span>Basically, ordered creation in a navigation container is a two pass beast and tricks the application into turning off the Preloader and moving on to frame two.<span style="">&nbsp; </span>During the first pass, the navigator&#8217;s immediate child views are created. It is at this point that the application thinks it can display and ends up moving to frame two.<span style="">&nbsp; </span>Then on the second pass the navigator&#8217;s child view&#8217;s children are created.<span style="">&nbsp; </span></font></font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">In this scenario, if we were to use bullet time, you&#8217;d see the application initially with&nbsp;instantiated but&nbsp;empty containers, and then you&#8217;d see their children pop into view as the Flash Player works its way through the instantiation queue.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here is an example of the app we&#8217;ve been working with creationPolicy=&#8221;queued&#8221;:</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_ORDERER/InsideRIA_CreationPolicy_ORDERER.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_CreationPolicy_ORDERER/InsideRIA_CreationPolicy_ORDERER.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">All in all, ordered creation is perceived as the fastest option of the three navigator children instantiation choices.<span style="">&nbsp; </span>Surprisingly, it&#8217;s even slightly faster than deferred creation which I guess makes sense since the first navigator child view&#8217;s children need to be created with deferred instantiation before moving to frame&nbsp;two whereas in ordered creation that is not the case.<span style="">&nbsp; </span></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"><span style=""></span></font>&nbsp;</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"><span style=""></span>In my tests, with the browser&#8217;s cache turned off, startup time in non-deferred creation was taking around 1100ms, deferred creation around 500ms, and ordered creation around 270ms.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">One last note on deferred instantiation in navigation containers: if you&#8217;re concerned with memory consumption, deferred instantiation A.K.A creationPolicy=&#8221;auto&#8221; - the default setting - is still the way to go in your navigation containers.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<div style="border-style: none none double; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 2.25pt; padding: 0in 0in 1pt;">
<p class="MsoNormal" style="border: medium none ; margin: 0in 0in 0pt; padding: 0in;"><b style=""><span style="font-family: 'Trebuchet MS','sans-serif';"><font size="3"><font color="#000000">EXPERIMENTAL: Take Advantage of the Stream<o:p></o:p></font></font></span></b></p></div>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Recently I discovered a blog post by a gentleman named Dirk Eismann that created a cool little Flex Builder plugin that I use every day.<span style="">&nbsp; </span>Flex Builder TODO/FIXME plugin. (</font><a href="http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757"><font color="#800080" face="Times New Roman" size="3">http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757</font></a><font color="#000000" face="Times New Roman" size="3">)<span style="">&nbsp; </span></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"><span style=""></span></font>&nbsp;</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"><span style=""></span>Anyway, his post mentioned taking advantage of the streaming nature of the Flash Player to minimize startup time in your Flex applications without having to use Modules or framework caching. (</font><a href="http://www.richinternet.de/blog/index.cfm?entry=FF295F89-DAD8-CCDC-960413842BC0D478"><font color="#800080" face="Times New Roman" size="3">http://www.richinternet.de/blog/index.cfm?entry=FF295F89-DAD8-CCDC-960413842BC0D478</font></a><font color="#000000" face="Times New Roman" size="3">)</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">The key thing to note about this technique is that it deviates from the standard two frame Flex application movie.<span style="">&nbsp; </span>Although I can&#8217;t take credit for his technique, I decided to&nbsp;expand his code snippets and details into a&nbsp;working example for this blog post which I got "mostly" done.</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3">&nbsp;</font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3">Here is the application I&#8217;ve been working with in a seven frame Flex application!</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><font color="#000000" face="Times New Roman" size="3"><a href="http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_MoreThanTwoFrames/InsideRIA_MoreThanTwoFrames.html">http://labs.realeyes.com/examples/InsideRIA/Part2/InsideRIA_MoreThanTwoFrames/InsideRIA_MoreThanTwoFrames.html</a></font></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font color="#000000" face="Times New Roman" size="3"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">The main thing to notice when you run the application is that you can interact with the first form that&#8217;s in frame three while all the other forms in the subsequent frames are loading in.<span style="">&nbsp; </span>I slowed frames four through seven down by embed