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

<channel>
	<title>Mike&#039;s Blabberings &#187; flex</title>
	<atom:link href="http://www.mike-griffith.com/blog/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mike-griffith.com/blog</link>
	<description>on software, testing, and the web.</description>
	<lastBuildDate>Tue, 29 Jun 2010 14:37:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Developing AIR apps for the desktop using the Flex 3 SDK for FREE</title>
		<link>http://www.mike-griffith.com/blog/2010/01/developing-air-apps-for-the-desktop-using-the-flex-3-sdk-for-free/</link>
		<comments>http://www.mike-griffith.com/blog/2010/01/developing-air-apps-for-the-desktop-using-the-flex-3-sdk-for-free/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 22:03:12 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.mike-griffith.com/blog/?p=308</guid>
		<description><![CDATA[One of the greatest things about Flex and Air is the low barrier to entry for us software geeks.  There&#8217;s nothing stopping any non-flash software dev from writing some kickass desktop apps.  There&#8217;s no reason you have to buy anything to start writing, testing, and distributing Adobe Air apps.  You don&#8217;t need [...]]]></description>
			<content:encoded><![CDATA[<p>One of the greatest things about Flex and Air is the low barrier to entry for us software geeks.  There&#8217;s nothing stopping any non-flash software dev from writing some kickass desktop apps.  There&#8217;s no reason you have to buy anything to start writing, testing, and distributing Adobe Air apps.  You don&#8217;t need their <a href="http://www.adobe.com/go/buyflexbuilder_std" target="_blank">fancy (unsupported) IDE, FlexBuilder</a>.  You don&#8217;t need to purchase a code signing certificate.  You don&#8217;t have to pay fees to get into a app store.  All you need is a terminal, some links to good samples and tutorials, and this article to get you moving in the right (hopefully) direction.</p>
<p><strong>Disclaimer</strong><br />
I&#8217;ve only spent a grand total of about 3 hours researching and coding anything flash-related.  Any information distributed here could lead you down a long and lonesome path &#8212; however, more likely, it&#8217;ll get your feet wet enough so that you can take off on your own adventure.</p>
<p><strong>Prerequisistes:</strong></p>
<ol>
<li>Download and install the <a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex3sdk" target="_blank">Adobe Flex SDK</a>.  I&#8217;m using Adobe Flex version 3.4 on Ubuntu 9.10</li>
<li>Have basic familiarity with a command line terminal (Linux, cygwin, etc.)</li>
</ol>
<p>Good so far?  Great.  Here&#8217;s what I hope to help you understand, because it was what I struggled with.</p>
<ol>
<li>Filesystem layout for your application</li>
<li>Writing your application, coding mxml and ActionScript</li>
<li>Packaging and signing your application</li>
<li>Installing and running your new application</li>
</ol>
<p>There are a lot of other more advanced topics that I&#8217;d like to learn myself, including but not limited to:</p>
<ol>
<li>Using third party libraries (.swc&#8217;s)</li>
<li>Unit testing your application with ASUnit</li>
<li>Upgrading your life with ANT buildscripts</li>
</ol>
<p><strong>Steps to writing your first air application:</strong></p>
<ol>
<li>Create a directory to hold this project and its source code.

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    $ mkdir myairapp
    $ mkdir myairapp/src</pre></div></div>

</li>
<li>Generate a new .mxml file inside your source code folder.

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    $ vim myairapp/src/MyAirApp.mxml</pre></div></div>

<p>FlexBuilder admittedly helps a ton here, but you don&#8217;t need it.  This file defines what your application will look like, using XML markup to indicate panes, widgets, and all sorts of fun stuff.  However, there&#8217;s no reason it can&#8217;t be done in VIM or your favorite text editor.  This file (along with your actionscript files) will likely be the most volatile part of the project as you continue to code.  Here&#8217;s a basic template you can download and use.  Stick this in your root source folder.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:WindowedApplication</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">xmlns:ns1</span>=<span style="color: #ff0000;">&quot;*&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">showTitleBar</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">showStatusBar</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">currentState</span>=<span style="color: #ff0000;">&quot;load_state&quot;</span> <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;load_state&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/mx:State<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">        private function init():void {</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">    ]]&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:WindowedApplication<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Update the &#8220;mx:states&#8221;, which will be used to represent different viewports/panes within this app.  Each state will have a button, and it will be a different color for each.  The first, named &#8220;load_state&#8221;, has a green button as defined by the &#8220;fillColors&#8221; attribute.  The second, named &#8220;clicked_state&#8221;, has a blue button.

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;load_state&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:AddChild</span> <span style="color: #000066;">position</span>=<span style="color: #ff0000;">&quot;lastChild&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;24&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;36&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;122&quot;</span> <span style="color: #000066;">fillAlphas</span>=<span style="color: #ff0000;">&quot;[1.0, 1.0]&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">fillColors</span>=<span style="color: #ff0000;">&quot;[#00FF00, #00FF00]&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Page 1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:AddChild<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:State<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:State</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clicked_state&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:AddChild</span> <span style="color: #000066;">position</span>=<span style="color: #ff0000;">&quot;lastChild&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;24&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;36&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;122&quot;</span> <span style="color: #000066;">fillAlphas</span>=<span style="color: #ff0000;">&quot;[1.0, 1.0]&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">fillColors</span>=<span style="color: #ff0000;">&quot;[#0000FF, #0000FF]&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Page 2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:AddChild<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:states<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Write some actionscript code to toggle between states when you click the buttons.  The currently visible one can be read and changed based on a global variable, `currentState`.

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> onState1ButtonClick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Go to the 2nd &quot;state&quot; when this button is clicked</span>
            currentState <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;clicked_state&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> onState2ButtonClick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Return to the initial &quot;state&quot; when this button is clicked</span>
            currentState <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;load_state&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>    Then, wire-up the events so that clicking will actually trigger the code.  Add a &#8220;click&#8221; attribute to the &#8220;mx:Button&#8221; element to match</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> ... <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;onState1ButtonClick()&quot;</span> ... <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> ... <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;onState2ButtonClick()&quot;</span> ... <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</li>
<li>The last thing you&#8217;ll need before you can play with your masterpiece is your &#8220;application.xml&#8221; file. Stick this in the main project directory, rather than in with your source code.

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    $ vim myairapp/MyAirApp-app.xml</pre></div></div>

<p>See the <a href="http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7ecc.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7fad" target="_blank">Adobe AIR documentation</a> for an example.
</li>
</ol>
<p><strong>Packaging, code signing, generating .air, and installing</strong><br />
Your app is *almost* ready to run.  The basic steps to get the app transformeed from source to binary are:</p>
<ol>
<li>Generate .swf with amxmlc</li>
<li>Generate code signing certificate with adt (alternatively, if you&#8217;re a linux whizbang you can use openssl)</li>
<li>Tweak your application .xml.  Link to .swf from step #1</li>
<li>Package it up into .air with adt</li>
</ol>
<p>I&#8217;ve created a shell script to automate the package, code signing, and generating air step. Copy this into &#8220;myairapp/build.sh&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">APP_NAME</span>=MyAirApp
<span style="color: #007800;">FLEX_BIN</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>flex_sdk_3.4<span style="color: #000000; font-weight: bold;">/</span>bin
&nbsp;
<span style="color: #666666; font-style: italic;"># build a .swf</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> release
<span style="color: #007800;">$FLEX_BIN</span><span style="color: #000000; font-weight: bold;">/</span>amxmlc .<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$APP_NAME</span>.mxml <span style="color: #660033;">-output</span> .<span style="color: #000000; font-weight: bold;">/</span>release<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$APP_NAME</span>.swf
&nbsp;
<span style="color: #666666; font-style: italic;"># generate code signing certificate</span>
<span style="color: #007800;">$FLEX_BIN</span><span style="color: #000000; font-weight: bold;">/</span>adt <span style="color: #660033;">-certificate</span> <span style="color: #660033;">-cn</span> <span style="color: #007800;">$APP_NAME</span> <span style="color: #000000;">1024</span>-RSA cert.pfx <span style="color: #007800;">$APP_NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># package into .air</span>
<span style="color: #007800;">$FLEX_BIN</span><span style="color: #000000; font-weight: bold;">/</span>adt <span style="color: #660033;">-package</span> <span style="color: #660033;">-storetype</span> pkcs12 <span style="color: #660033;">-keystore</span> cert.pfx \
    <span style="color: #660033;">-storepass</span> <span style="color: #007800;">$APP_NAME</span> \
    .<span style="color: #000000; font-weight: bold;">/</span>release<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$APP_NAME</span>.air .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$APP_NAME</span>-app.xml .<span style="color: #000000; font-weight: bold;">/</span>release<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$APP_NAME</span>.swf \
    <span style="color: #666666; font-style: italic;"># Uncomment the following lines if you have icons that you have created</span>
    <span style="color: #666666; font-style: italic;">#-C assets icon_16.png \</span>
    <span style="color: #666666; font-style: italic;">#-C assets icon_32.png \</span>
    <span style="color: #666666; font-style: italic;">#-C assets icon_48.png</span></pre></div></div>

<p>Now execute the build script. Assuming there were no errors, your new application is ready to be installed.  Open up the newly generated .air file in the release directory, and the air installer should walk you through the install process.</p>
<p>If you want to start getting fancier, the next step you&#8217;ll want to do is externalize your ActionScript code.  All you have to do is create a &#8220;.as&#8221; file (or an entire directory if you want to break up your code into namespaces), stick it next to the .mxml, and then you&#8217;ll be able to &#8220;import&#8221; it and use functions, classes, etc from it.  I prefer to keep the actual event wiring within the .mxml code, but don&#8217;t let it get too cluttered.</p>
<p>Additionally, you&#8217;ll want to start adding assets (icons, images, sound files, etc) to your project.  Create a separate &#8220;assets&#8221; directory to hold them.</p>
<p>Additional Flex development references</p>
<ul>
<li><a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK">http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK</a></li>
<li><a href="http://www.adobe.com/devnet/flex/">http://www.adobe.com/devnet/flex/</a></li>
<li><a href="http://flex.org/">http://flex.org/</a></li>
<li>To find great examples, search Google for &#8220;flex site:googlecode.com&#8221;</li>
</ul>
<p>More help with compiling and packaging:</p>
<ul>
<li><a href="http://www.adobe.com/devnet/air/articles/signing_air_applications_print.html">http://www.adobe.com/devnet/air/articles/signing_air_applications_print.html</a></li>
<li><a href="http://blog.devsandbox.co.uk/?p=163">http://blog.devsandbox.co.uk/?p=163</a></li>
<li><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html#150640">http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html#150640</a></li>
</ul>
<p>Best of luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffith.com/blog/2010/01/developing-air-apps-for-the-desktop-using-the-flex-3-sdk-for-free/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
