Wednesday, December 01, 2010

Mobile Development with Flash Builder (Tutorial and Source Code)


Today I am releasing a set of two applications, one built using the Flex 4.1 SDK and one built using the Flex 4.5 SDK (Burrito version of Flash Builder using the "Hero" framework).  Although the base application is essentially the same, the differences are astounding in terms of development ease and performance. 

The project itself is a simple project to demonstrate how to read/write to a file system.  The application is named LetMeC (“let me see”).   The screenshot below is of the application built using Flash Builder 4.01 overlaid with the AIR 2.5 SDK.  This one uses the FileSystemDataGrid component and has several helper classes.  The source code for the AIR 2.5 project is available here: 

FileBrowser.fxp (Flash Builder 4.01/AIR 2.5 SDK project - 76 kb)
FileBrowser.apk (Android Package - 1.02 MB)
Installed application size = 1.02 MB (without graphics, icons, splash images etc)



This second screenshot (below) is basically the same application written using the Flash Builder 4.5 Burrito preview.  This application is open and you can use it or install it on your device:

MobileFileBrowser.fxp (Flash Builder 4.5 project - 840 kb)
MobileFileBrowser.apk (Android Package -1.78 MB)
Installed application size = 768 kb (with graphics, icons, splash images etc)



Note that the installed sizes of the applications vary.  The first one is larger even though I never used any graphics for icons, splash screens or other bits.  The Flash Builder 4.5 Burrito application has a larger installer, however on the Google Nexus 1 disk, the installed application is only 768 kb, of which roughly 398 kb is images alone coupled with 230 kb of icons!  The Hero framework rocks! Here is a screenshot.




The differences in development are vast and I am definitely favoring the direction Adobe is running towards with respect to the Hero framework.  Mobile development in Flash Builder 4.5 is much easier.  For starters, there is a notion of "views" and features such as screen orientation are supported.  The first thing you will notice is that the list of components is greatly reduced.  The version of this I built using 4.1 used the component.  This component by itself is very heavy weight (it is still MX or Halo qualified, not Spark).  The scroll bars are difficult to use as the hit area on a touch screen is very small.  Also the orientation is something you have to do manually if you want your application to resize and reorient when the phone is tilted.

One item that works well on PC, Mac, and Linux is AIR’s “openWithDefaultApplication()” method.  No such luck on Android as the architecture uses a notion of “intents”.   It is easy to write code to access the functionality rather than accessing the notion of a "file".  One line of code will open up an SMS, URL, or even phone someone.  As the code samples from James Ward illustrate below:



Last thoughts?  I am now addicted to mobile development!  Adobe Flash Builder 4.5 rocks (even though it is a preview and somewhat "beta").  The most beautiful thing is that I can use 95% of my code for a desktop application too.

Try it for yourself.  Download the Flash Builder 4.5 preview from http://labs.adobe.com

I will post a video of this whole process very shortly on this blog.

Peace, love and may your code compile on the first try!

10 comments:

  1. Thank you sir for the post. I'll be waiting anxiously on the video.

    ReplyDelete
  2. I built an app with Hero and I thought it was real easy as well. Worked great on my Droid 2. I then used that swf and ran the iPhone Packager on it and tried it on my iPhone 4 and it was a disaster. The text field focus was buggy (had to click multiple times to get keyboard) and in some cases focus transferred to the logo in my title content. Still optimizing...but performance is bad even with pure AS3 swfs.

    ReplyDelete
  3. Check out how I took the MobileFileBrowser project and got it running on the BlackBerry PlayBook
    http://renaun.com/blog/2010/12/browse-files-on-playbook/

    ReplyDelete
  4. The video is now posted at http://technoracle.blogspot.com/2010/12/video-article-comparing-air-for-android.html

    ReplyDelete
  5. This app is now in the Android market. Just search for "LetMeC". Any ideas for improvements would be appreciated too if you find it useful.

    Duane

    ReplyDelete
  6. Hi, you mentioned that openWithDefaultApplication() does not work on Android. I tried navigateToURL(new URLRequest("file:///[localfilepath])) does not work.

    Any way to launch the local file as a file browser is good, but would be even better if I could open the file in appropriate viewer (i.e. pdf file in Adobe PDF viewer or any other viewers registered on device).

    ReplyDelete
  7. @asdfasdf I have been trying this too but suspect that there is a filter on the intent as it could be used maliciously (not sure what the additional exposure is). As you've already probably noted, you can create the intent for an SMS, Email, telephone call or external URL but trying to navigate to the local file doesn't work right now. I've seen other applications do this on my Galaxy Tab so I am curious. I will be reading the API docs from Google over the coming days.

    ReplyDelete
  8. Hi Duane,
    I wonder if there is any news in regards to openWithDefaultApplication() on Android/iOS. Is/would it be supported (e.g. in 4.6) or is the native extension the right way to implement a "workaround"?

    ReplyDelete
  9. I am not sure. I no longer work for Adobe. They laid off a bunch of their staff dedicated to helping enterprises and developers. I now work for Uberity and haven't really been interested in the products much more since November 8. You might want too ping some of the remaining Adobe staff. I asked them before but got no answer. Best of luck finding a solution.

    Duane

    ReplyDelete
  10. force close in my galaxy ace, anyone know why ?

    ReplyDelete

Do not spam this blog! Google and Yahoo DO NOT follow comment links for SEO. If you post an unrelated link advertising a company or service, you will be reported immediately for spam and your link deleted within 30 minutes. If you want to sponsor a post, please let us know by reaching out to duane dot nickull at gmail dot com.