I was certainly very excited about the new SDK regarding to mobile development. Lately many clients ask about mobile support for their applications and slowly all projects become multi target (web, local, tablet, mobile) This imply a difficult migration, running around some CSS magic or even writing versions in Objective C to target IOS platform.
So is possible to develop once and deploy to any target? Well, not really, but with a good design, we’re almost there. The new SDK can target Android devices in his debut, and promise to support IOS devices (via cross-compiling to Objective C) and Blackberry Playbook in the near future (update in June … or probably is a fact when you read this)
The process is straightforward: you need to create a Flex Mobile Project or an ActionScript Mobile Project from the File menu and a wizard will help you target the correct device. As stated, currently only Android devices are available, but the concrete model doesn’t matter since you can change device target at any point (always inside Android family with version 2.2 Froyo at least) About UI there are a couple of mechanism that helps in adequate to the different screens and resolution:
- You should constrain or your containers, say a List, to keep a certain distance from borders instead of give a fixed size, this ensures an adaptable layout
- There’s a multi DPI mechanism to adapt to different screen density trough rescaling (typically 160, 240 and 320) so your UI remain the same. For bitmaps you can use the MultiDPIBitmapSource tag to provide different graphics for each
There are a few foundation components to navigate applications: View based application (default) and tabbed based application. The first one use a stack of screen to push and pop different applications screens, creating and destroying them on the fly so memory consumption doesn’t growth. Since screens are destroyed on demand, data persists because the application could be interrupted at any moment (because a call i.e) and you should be able to restore at the same point, or go back to a previous screen. Data is injected as the data property at any view. Tabbed applications works similarly, but instead of scrolling from screen to screen, you just tab between them.
Here’s a sample code of the Twitter Trends demo, showing the initial application template
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.TwitterTrendsHomeView"
persistNavigatorState="true">
<s:actionContent>
<s:Button id="refreshBtn" click="Object(navigator.activeView).refresh()">
<s:icon>
<s:MultiDPIBitmapSource source160dpi="@Embed('assets/refresh160.png')"
source240dpi="@Embed('assets/refresh240.png')"
source320dpi="@Embed('assets/refresh320.png')"/>
</s:icon>
</s:Button>
</s:actionContent>
</s:ViewNavigatorApplication>
Another important thing to remark is that mobile aware components were updated to perform smooth on mobile devices, and in this sense should be considered “light” components, while web components are more resource intensive consumers, so are not a good choice for mobile apps. Articles emphasize in simple skins and programmatic itemrenderers (based on ActionScript, not on MXML) to gain a better performance.
Finally some thoughts about architecture. If you want to develop once and deploy to multiple target you can do … partially. All the business and services domain can be the same, but view will change between different targets. So suppose you want to have your web application available for mobiles, you can follow some MVP or MVC pattern (Model-View-Presenter or Model-View-Controller) so View related code keeps on each project, while data, business and services access can be shared. Almost all of the traditional Flex frameworks emphasize this structure, and if you follow some of them probably will not be difficult to adapt to this structure (if not, read flex frameworks)
To start on this topic, Adobe have many articles and examples, you can begin reading about the topics commented here but more in deep reading a mobile reference or check a list of examples as a basement for your own. We’re planning our own example very soon, so stay tuned.











