<?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>Luminis Software Development &#187; Flex / AIR</title>
	<atom:link href="http://lsd.luminis.eu/category/flex-air/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.eu</link>
	<description></description>
	<lastBuildDate>Sun, 03 Mar 2013 08:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>nl</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GraniteDS and AIR for mobile</title>
		<link>http://lsd.luminis.eu/graniteds-and-air-for-mobile/</link>
		<comments>http://lsd.luminis.eu/graniteds-and-air-for-mobile/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 14:10:51 +0000</pubDate>
		<dc:creator>Walter Treur</dc:creator>
				<category><![CDATA[Flex / AIR]]></category>
		<category><![CDATA[iPhone/ iPad]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[graniteds]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[News Item]]></category>

		<guid isPermaLink="false">http://lsd.luminis.eu/?p=1571</guid>
		<description><![CDATA[In this short article I will show how to resolve some obstacles I came across when I developed my first application with AIR for mobile and GraniteDS]]></description>
			<content:encoded><![CDATA[<p>In this article I will briefly show how to resolve some obstacles I came across when I developed my first application with <a href="http://www.adobe.com/devnet/devices.html">AIR for mobile</a> and <a href="http://www.graniteds.org">GraniteDS</a>. The most noteworthy reason of using AIR to create mobile applications is of course the <a href="http://lsd.luminis.eu/introduction-to-air-for-mobile/">multi-platform deployment using a single codebase</a>. Furthermore, with Granite you are able to disclose the services of an existing Java backend to a mobile platform without significant changes to the backend. This offers great potential for enterprises who are struggling with the fragmented mobile market and don’t want to completely rewrite their existing Java backend.</p>
<p>I will assume you have some familiarity with AIR for mobile and Granite. It’s mostly the same as for Flex but there are some things you have to take into account.</p>
<h3>1. Get the right version of Granite</h3>
<p>The latest version of Granite is 2.2.1 GA. However, in the most recent version of AIR and Flex Adobe made some changes in the API which breaks backwards compatibility for some features of Granite. Therefore this release of Granite won’t work using the newest SDK. Refer to <a href="https://groups.google.com/d/msg/graniteds/1avtq0rXezU/0JPcX0wTTWYJ">this post on the Granite form</a> for more info on how to make these changes yourself. If you don’t want be bothered with building Granite yourself just download <a href="http://lsd.luminis.eu/wp-content/uploads/2011/09/graniteds-mobile-air.zip">this version of GraniteDS</a> to get started immediately.</p>
<h3>2. Connecting to the right server</h3>
<p>A problem for AIR applications in general (both desktop and mobile) is setting the right server settings. It is quite simple when running within the browser: The server address is changed with a single reconfiguration of the swf-file and all clients are using the new address on a browser refresh. With AIR it is a bit different and you&#8217;re not always at liberty to ‘hardcode’ the service settings in the AIR distribution package.<br />
Granite offers a method for dynamic server configuration using the server initializer component:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Tide.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addComponentWithFactory</span><span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;serviceInitializer&quot;</span>,
  DefaultServiceInitializer, <span style="color: #66cc66;">&#123;</span>
    contextRoot: <span style="color: #ff0000;">'/my-app'</span>,
    serverName: “10.0.0.1”,
    serverPort: “<span style="color: #cc66cc;">8080</span>”
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Note that once a connection is made, it is not possible to reconnect with another configuration, because the service initializer is only used once. You have to restart the application to enable the new connection settings or reset Tide’s RemoteObject. Unfortunately Tide’s API doesn’t support this reset. I came up with a small workaround which requires you to extend the EJB class with an extra reset method with the following body:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Ejb <span style="color: #0066CC;">extends</span> org.<span style="color: #006600;">granite</span>.<span style="color: #006600;">tide</span>.<span style="color: #006600;">ejb</span>.<span style="color: #006600;">Ejb</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">/**
   * Reset the Tide Connection to allow new server settings
   */</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resetConnection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_ro<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      _ro.<span style="color: #006600;">disconnect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    _ro = <span style="color: #000000; font-weight: bold;">null</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method resets Tide’s RemoteObject so the next remote call will force a reinitialization using the current settings of serviceInitializer. Refer to <a href="http://www.graniteds.org/jira/browse/GDS-913">Granite’s issue tracker</a> or <a href="https://groups.google.com/d/msg/graniteds/wITFxXyXTYw/3hMnwH76T6sJ">forum thread</a> for more details.</p>
<h3>3. Automatic logout</h3>
<p>Applications running on mobile platforms are always susceptible to unpredictable interruptions. For example when a phone call or text is received. Mobile AIR applications provide a <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html#event:deactivate">deactivate event</a> which is dispatched when the application is halted somehow. The application I wrote was using Tide’s Identity class for user login. Therefore I added an event handler to automatically logout the user and push the LoginView on top of the navigator stack:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> deactivateHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>identity.<span style="color: #006600;">loggedIn</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    identity.<span style="color: #006600;">logout</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  navigator.<span style="color: #006600;">popAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Purge the navigator history to disable back button usage</span>
  navigator.<span style="color: #006600;">pushView</span><span style="color: #66cc66;">&#40;</span>LoginView<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>4. Build, build, build!</h3>
<p>This isn’t directly related to Granite or AIR for mobile. But since they can both be used for enterprise scale applications I thought I&#8217;d mention it shortly: Make sure you have a proper build script. Now, I’ve got an example from <a href="http://www.blackcj.com/blog/2011/04/04/ios-android-and-blackberry-in-a-single-click-with-ant/">Chris Black</a> which provides a good starting point. I’ve only added the metadata compiler options required for Tide and of course a reference to the Granite libraries and generated Actionscript classes.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mxmlc</span> ... <span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- .... --&gt;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- location of generated as classes with gas3 --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source-path</span> <span style="color: #000066;">path-element</span>=<span style="color: #ff0000;">&quot;${gen.src.dir}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compiler.library-path</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${basedir}/libs&quot;</span> <span style="color: #000066;">append</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;granite-essentials.swc&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>   
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;granite.swc&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/compiler.library-path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Bindable&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ChangeEvent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Destroy&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Id&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;In&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Inject&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Managed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ManagedEvent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Name&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NonCommittingChangeEvent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Observer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Out&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;PostConstruct&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Transient&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep-as3-metadata</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Version&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mxmlc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>One plus one</h3>
<p>I can imagine one must be thinking: ‘Everyone could have figured that out!’ And I totally agree, because that’s exactly what this article is about. With some experience with Flex, a developer can write a mobile application on top of a Java EE backend. It doesn’t take much to utilize an existing backend from a mobile platform. Since the latest release of AIR the performance for iOS and Android is pretty good and together with the <a href="http://www.granitedataservices.com/enterprise-platform-2011/">Granite Enterprise Platform</a> the barrier to emerge an enterprise application to a mobile platform has become much lower.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/graniteds-and-air-for-mobile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to AIR for mobile</title>
		<link>http://lsd.luminis.eu/introduction-to-air-for-mobile/</link>
		<comments>http://lsd.luminis.eu/introduction-to-air-for-mobile/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 15:21:25 +0000</pubDate>
		<dc:creator>Walter Treur</dc:creator>
				<category><![CDATA[Flex / AIR]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[Google Android]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[News Item]]></category>

		<guid isPermaLink="false">http://lsd.luminis.eu/?p=1209</guid>
		<description><![CDATA[A couple of weeks ago, Adobe released a preview of the new Flash Builder and SDK. One of the new features is support for mobile devices using AIR. For now, only Android 2.2 is capable of running mobile AIR applications, but since Steve has changed the rules again, AIR on iOS is nearby, according to Adobe. Time to take a test drive with a tutorial.]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago, Adobe released a preview of the new Flash Builder and SDK. One of the new features is support for mobile devices using AIR. For now, only Android 2.2 is capable of running mobile AIR applications, but since Steve has changed the rules again, AIR on iOS is nearby, according to Adobe. Time to take a test drive with a tutorial.</p>
<h3>Goal</h3>
<p>We will create a simple RSS reader. Not a very exciting example, but already shows some nice features of AIR for mobile. I’ll assume you have experience with Flex or AIR, but I think you will manage with some level of programming experience. If not, feel free to leave a reply if you have any questions or take a look at the <a href='http://lsd.luminis.eu/wp-content/uploads/2010/11/MobileRssReaderTutorial.zip'>full source</a>.</p>
<h3>Setup</h3>
<p><img src="http://lsd.luminis.eu/wp-content/uploads/2010/11/empty-project-contents.png" alt="Empty project contents" title="Empty project contents" width="269" height="196" class="alignleft size-full wp-image-1258" /></p>
<p>Download and install the preview release of <a href="http://labs.adobe.com/technologies/flashbuilder_burrito/">Flash Builder called Burrito</a> It provides a wizard to start an empty mobile application. By default the wizard creates two mxml files containing a MobileApplication and a View component.</p>
<p>The MobileApplication class is inherited from the Application class used for desktop AIR. The mobile version provides, among other things, an action bar and a navigator. Furthermore its firstView property points to the empty view component. The view component is a normal group, but optimized for mobile use as well.</p>
<h3>Article list</h3>
<p>Open the main view component (called <i>&lt;projectName&gt;</i>Home.mxml). Create a List component in the main view. Provide positioning constraints to let it occupy the whole screen.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> left=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>To retrieve the feed, create an HTTPService pointing to the RSS feed in the declaration section of the view. Add a resultHandler function to parse the feed-data. Parsing xml data is quite simple. You can just navigate to the DOM-tree as it were a normal ActionScript object. Use the data property of the view to store the articles locally. Using this property will provide some benefits with navigation, which will become clear in a bit.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">    import mx.rpc.events.ResultEvent;</span>
&nbsp;
<span style="color: #000000;">    protected function service_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">      data = event.result.rss.channel.item;</span>
<span style="color: #000000;">    <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HTTPService</span></span>
<span style="color: #000000;">    id=<span style="color: #ff0000;">&quot;service&quot;</span></span>
<span style="color: #000000;">    url=<span style="color: #ff0000;">&quot;http://lsd.luminis.nl/feed/&quot;</span></span>
<span style="color: #000000;">    result=<span style="color: #ff0000;">&quot;service_resultHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Now there are only a couple of things left to do. Invoke the server and provide the list with the articles and instructions to show them.</p>
<p>Both are quite simple. The feeds are retrieved by invoking the send() method of the service. To automatically retrieve them, this method should be invoked when the view is created so we will use the creationComplete handler.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:View</span></span>
<span style="color: #000000;">  xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  title=<span style="color: #ff0000;">&quot;Home&quot;</span></span>
<span style="color: #000000;">  creationComplete=<span style="color: #ff0000;">&quot;service.send()&quot;</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Finally, bind the data property to the dataProvider of the list and set its labelField attribute to ‘title’.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span></span>
<span style="color: #000000;">  dataProvider=<span style="color: #ff0000;">&quot;{data}&quot;</span></span>
<span style="color: #000000;">  labelField=<span style="color: #ff0000;">&quot;title&quot;</span></span>
<span style="color: #000000;">  left=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>Your view will probably look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:View</span></span>
<span style="color: #000000;">  xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  title=<span style="color: #ff0000;">&quot;Home&quot;</span></span>
<span style="color: #000000;">  creationComplete=<span style="color: #ff0000;">&quot;service.send()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">      import mx.rpc.events.ResultEvent;</span>
&nbsp;
<span style="color: #000000;">      protected function service_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">        data = event.result.rss.channel.item;</span>
<span style="color: #000000;">      <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">    <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HTTPService</span></span>
<span style="color: #000000;">      id=<span style="color: #ff0000;">&quot;service&quot;</span></span>
<span style="color: #000000;">      url=<span style="color: #ff0000;">&quot;http://lsd.luminis.nl/feed/&quot;</span></span>
<span style="color: #000000;">      result=<span style="color: #ff0000;">&quot;service_resultHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span></span>
<span style="color: #000000;">    dataProvider=<span style="color: #ff0000;">&quot;{data}&quot;</span></span>
<span style="color: #000000;">    labelField=<span style="color: #ff0000;">&quot;title&quot;</span></span>
<span style="color: #000000;">    left=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:View</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<h3>Emulator</h3>
<div id="attachment_1254" class="wp-caption alignleft" style="width: 172px"><img src="http://lsd.luminis.eu/wp-content/uploads/2010/11/emulate-hardware-buttons.png" alt="Emulate hardware buttons" title="Hardware buttons" width="162" height="138" class="size-full wp-image-1254" /><p class="wp-caption-text">Emulate hardware buttons</p></div><br />
Now it is time to run a first test. Click the Run button and select ‘On Desktop’ as launch method in run configuration dialog. Also choose a device to simulate and run the application.</p>
<p>When the emulator is launched it shows a list of articles after a couple of seconds. Now you can select Rotate Right from the Device menu to display the landscape view. You will also notice the list is able to scroll up and down when dragging your mouse pointer (Which of course is the emulated equivalent of a one-finger swipe)</p>
<h3>Article details</h3>
<p>Next is to create a detailed view showing the full content of an article. Close the emulator and return to Flash Builder. In the views package, create a new component and call it DetailView. Bind the title attribute to data.title. Add a label as well and bind the text property to data.description. Don’t forget to specify the positioning constraints.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:View</span></span>
<span style="color: #000000;">  xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  title=<span style="color: #ff0000;">&quot;{data.title}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span></span>
<span style="color: #000000;">    text=<span style="color: #ff0000;">&quot;{data.description}&quot;</span></span>
<span style="color: #000000;">    left=<span style="color: #ff0000;">&quot;20&quot;</span> right=<span style="color: #ff0000;">&quot;20&quot;</span> bottom=<span style="color: #ff0000;">&quot;20&quot;</span> top=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:View</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>All view components provide a navigator object. We will use this in the change event handler of the article list. This event is fired when the user selects an article from the list. It looks as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">events</span>.<span style="color: #006600;">IndexChangeEvent</span>;
&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> articleList_changeHandler<span style="color: #66cc66;">&#40;</span>event:IndexChangeEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  navigator.<span style="color: #006600;">pushView</span><span style="color: #66cc66;">&#40;</span>DetailView, <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span>event.<span style="color: #006600;">newIndex</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>It simply instructs the navigator to create a new DetailView and push it on top of of the navigation stack. Furthermore the selected item from the article list is passed on to the data property of the DetailView.</p>
<p>Add the change handler and assign it to the change event of the article list:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span></span>
<span style="color: #000000;">  dataProvider=<span style="color: #ff0000;">&quot;{data}&quot;</span></span>
<span style="color: #000000;">  labelField=<span style="color: #ff0000;">&quot;title&quot;</span></span>
<span style="color: #000000;">  change=<span style="color: #ff0000;">&quot;articleList_changeHandler(event)&quot;</span></span>
<span style="color: #000000;">  left=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p><div id="attachment_1231" class="wp-caption alignright" style="width: 204px"><img src="http://lsd.luminis.eu/wp-content/uploads/2010/11/article-list-194x300.png" alt="Article list inside the emulator" title="Article list inside the emulator" width="194" height="300" class="size-medium wp-image-1231" /><p class="wp-caption-text">Article list inside the emulator</p></div>
<p>For performance optimization, AIR destroys the view when a user navigates away and recreates it when he returns. Only the contents of the data property is saved and passed into a recreated view of the same type. This is why we used it to store the articles. Otherwise the user has to wait for a reload when he returns to the main view.</p>
<p>When you launch the new version in the emulator, you will notice the application slides to the detail view when an article is selected. Click Back from the Device menu to simulate a click on the hardware back button.</p>
<h3>Last but not least: action buttons</h3>
<p>One thing our application is missing, is a button to go to the original webpage showing the full article. This button is placed inside the header of our detail view, next to the title.<br />
To achieve this, add the button inside the actionContent of the detail view. Give the button an icon (I used one from the <a href="http://tango.freedesktop.org/">Tango project</a>) and set the click handler to open the url of the article.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:actionContent</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span></span>
<span style="color: #000000;">    click=<span style="color: #ff0000;">&quot;{navigateToURL(new URLRequest(data.link))}&quot;</span></span>
<span style="color: #000000;">    icon=<span style="color: #ff0000;">&quot;@Embed('/assets/internet-web-browser.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:actionContent</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Of course you might want an additional button to return to the article list instead of using the ‘hardware button’. Place this button inside the navigationContent. This will place the back button at the upper left corner. The click event of this button will invoke the navigation.popView() method to remove the current view from the stack and return to the previous one.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:navigationContent</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span></span>
<span style="color: #000000;">    click=<span style="color: #ff0000;">&quot;navigator.popView()&quot;</span></span>
<span style="color: #000000;">    icon=<span style="color: #ff0000;">&quot;@Embed('/assets/go-previous.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>		
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:navigationContent</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<div id="attachment_1237" class="wp-caption alignleft" style="width: 310px"><img src="http://lsd.luminis.eu/wp-content/uploads/2010/11/action-buttons-300x112.png" alt="Action and navigator buttons" title="Action and navigator buttons" width="300" height="112" class="size-medium wp-image-1237" /><p class="wp-caption-text">Action and navigator buttons</p></div>
<p>If you launch the application you will notice the buttons are nicely aligned at the top of the screen.</p>
<h3>What’s next?</h3>
<p>The next step will be to package the application to an apk file so you could install it on an Android device. This is done by the Export Release build wizard inside the Project menu of Flash Builder. It includes the ability to sign your application to allow distribution through the Android Market.</p>
<p>Another nice feature which I will not discuss in detail is to add gesture based navigation. Take a look at this <a href="http://www.adobe.com/devnet/flash/articles/multitouch_gestures.html">article from Adobe</a> to find out more. The approach discussed should be working for mobile AIR applications as well.</p>
<p>Unfortunately the most interesting benefit of using AIR for mobile didn’t become clear with this tutorial. It would be nice to deploy our application on other mobile plastforms as well. However the cross compiler for iOS isn’t available yet and the same goes for AIR on Windows Phone, BlackBerry or Symbian. We will just have to wait when Adobe is ready so we can fully benefit from the “Write once, run anywhere” promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/introduction-to-air-for-mobile/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
