Wednesday, May 4, 2011

Develop for mobile devices using Flash platform

The dust has settled over this year Adobe MAX conference (my colleague, Serge Jespers, has been thinking about the next year’s conference for the past two months but this is another story :D).  So, by now, you should have heard most of the news around the Flash Platform and mobile devices. However, if you haven’t yet tried to build your first “Hello World” application, read on because it is really simple for us, Flash developers.

In this post I want to help you understand what tools and workflows you can use and what devices you can target. Please keep in mind that this post is about what is available today. We are working hard to make mobile development easier so expect to see more news from us in the future.
First of all when you want to build apps for mobile you’ll use Adobe AIR and its APIs. The biggest difference between AIR apps for mobile and those for desktops is that you can use only ActionScript or Flex for mobile apps (for desktop apps you can also use HTML/JavaScript/CSS). In terms of APIs, there are also some differences; but more on this later.
What applications can you build using AIR and ActionScript/Flex for mobiles? I think there are four main categories:
  • Games. There isn’t much to explain here. The same Flash games you see on the Internet can run inside of an AIR app packaged for mobile devices. There is even support for GPU acceleration.
  • RIA/Connected appsMAX Companion is a good example.
  • Enterprise apps. You can leverage existing services easily and expose them as mobile applications.
  • Remote Controls for desktop apps. My friend Luca Mezzalira created such an application for iPhone and Android. This app controls a desktop AIR application that is a presentation tool. From your mobile phone you can advance to the next slide or go back to the previous one. You can draw on the slides using the phone screen.

iOS devices (iPhone, iPod Touch, and iPad)

I’ll start with iOS because, historically, it is the first mobile platform we supported. We announced this back in 2009 at Adobe MAX and we released the Packager for iPhone this year as part of the Creative Suite 5 launch. If you want to develop applications for iOS you can use Flash Professional CS5 (Packager for iPhone is a feature of Flash Professional) – make sure you have updated the program to the 11.0.2 update. You can find the links for download and more info here. This will give you a new type of project: iPhone OS.
You can debug the application right from Flash Professional either using the AIR emulator (ADL) or directly on the device (the iPhone/iPod must be connected on the same WiFi network as the computer on which the debugger is running. If you want to learn how to setup Flash Professional for building iPhone apps on Windows (it is simple on MacOS actually) I recommend you watch thisscreencast, and on this blog you’ll find many posts about iPhone development using ActionScript.
Here are some of the specific APIs available when targeting iOS devices:
  • MultiTouch
  • Screen Orientation
  • Saving images to Photo Library
  • Accelerometer
  • Geo-location
  • Cut / Copy / Paste
What you can’t use today
  • RTMPE
  • PixelBender Filters
  • Microphone Access
  • Video Camera Access
Also, you can’t execute code from an SWF loaded at runtime because there is no virtual machine (you can use assets like images or animations). Basically in order to create an iOS app the AIR runtime is compiled together with your application code into iOS native code. This is the biggest difference between iOS and Android/BlackBerry (the AIR runtime is installed on the Android/BlackBerry device).
You’ll write your application using ActionScript. While using Flex is technically possible I strongly suggest you do not use it for now. Today, for iOS we are using AIR 2.0.1. For Android and BlackBerry we are using AIR 2.5. Flex “Hero” – the current Flex framework version under development that brings support for mobile requires AIR 2.5. We are working to bridge this gap (if you wonder why this differences exists, recall the whole story with 3.3.1 and the reverting of it).

Android

This year, on October 7th, we launched Adobe AIR 2.5 on Android Market for FroYo devices (phones running Android 2.2). A couple of days later we launched a preview release of our next generation tools for developing applications for the Flash Platform: Flash Builder “Burrito”, Flash Catalyst “Panini”, and Flex “Hero” framework. From Adobe Labs you can download Flash Builder “Burrito”. Once you have downloaded it you are ready to create Android applications using either ActionScript or Flex. You can use Flash Builder to develop your application, test it on your computer using an emulator, deploy the app to your Android device using the USB cable, or debug the application while running on the device. And when you are ready to submit the application to Android Market you can use the Flash Builder Export Release feature to build the APK file. Of course you can use Flash Professional CS5 too.
As I’ve already said, on Android, an AIR application uses the AIR runtime from the phone. So what is happening when a user decides to install an Android application built with AIR and he doesn’t have the AIR runtime installed? The installation process goes as usual and when he starts the application he is prompted with a message that explains that Adobe AIR is required for that application. If the user chooses “Install” the AIR runtime will be installed like any other Android application.
One question I’m asked is if it is possible to pack the AIR runtime with your AIR application. The answer is no.
Flex “Hero” enables you to easily create Android apps by adding new components specifically designed for mobile and optimizing existing components. You have, for example, support for screen management: your application can have the UI split between multiple screens with only one visible. Here is an article that will bring you up to speed. If you want to learn how to debug your code you can watch my friend, Ryan Stewart, explaining the process.
Here are some of the APIs available when using AIR for building Android apps:
  • Camera and Microphone Access
  • Accelerometer
  • GPS
  • StageWebView
  • Multitouch/Gestures
  • Screen Orientation / Fullscreen
  • Phone/SMS/Email/Browser/Android Market Integration
  • Session Cache Support – Restore App State
  • Hardware Buttons Support
  • Local Databases SQLite
  • Support for Android Permissions (Internet/SDCard access/GPS/Camera/etc.)
Finally, don’t forget about these two apps that can help you with Android development: Tour de Mobile Flex (this is an Android application built with AIR and Flex “Hero”) and Adobe AIR Launchpad (a desktop app that creates a Flex project ready for importing in Flash Builder with Android permissions set).

BlackBerry

With RIM’s announcement of the BlackBerry PlayBook the Flash Platform has been extended once again. Many of the things I said about AIR for Android development are true for BlackBerry PlayBook too. RIM integrated AIR right in the middle of their OS for this device and this makes us, Flash developers quite happy.
So what it is different compared to Android development with AIR? First of all you need to use theBlackBerry Tablet OS SDK and Simulator.  If you want to use Flash Builder “Burrito” then you are good to go once you downloaded the BlackBerry Tablet OS SDK and Simulator. If you want to quickly learn how to setup Flash Builder for PlayBook development watch Ryan Stewart’sscreencast .
Next, if you want to make your application look like the native apps (some of them are actually created using AIR) you can use the  BlackBerry Tablet OS SDK for Adobe AIR. Don’t let the name scare you, because this SDK basically does two things: provides a library of UI classes that are the same classes used by the PlayBook itself and enables you to package and deploy PlayBook applications (.bar) to the PlayBook simulator. For example, using these resources you can access the battery level or get a notification when a low memory event occurs. You can have a look and these APIs here. Fellow evangelist Renaun Erickson has written a number of posts on PlayBook development. In a nutshell you can develop applications using Flex “Hero” or just ActionScript.
As in the case of Android, you can use Flash Professional CS5 if you want – here is a goodtutorialBen Forta explains how you can set up Flash Professional CS5 for BlackBerry Playbook development.
We are working together with RIM to make it easier to build apps for BlackBerry PlayBook with Flex “Hero”, so stay tuned.
Finally, RIM offers a free tablet for those who create an application that gets accepted inBlackBerry App World.

Conclusions

As you see, by using the Flash Platform you can truly achieve multi-screen development. Today, you can create applications for desktops (Win/Mac OS/Linux) and iOS/Android/BlackBerry Tablet OS devices. Working with our partners from the Open Screen Project we will bring the Flash Platform to Windows Mobile 7, Palm webOS, and MeeGo/Symbian.
Of course moving AIR applications from desktops to mobile is not always a straightforward task. However if you architect your application carefully this task will be fun. Christian Cantrell andSerge Jespers have some good examples on this subject.
I really think that these are exciting times to be a Flash developer. There are tons of opportunities to do what you like to do, be innovative, and make money while doing so.

Where to go next

I hope I’ve made you curious enough to try out mobile development with the Flash Platform. And don’t forget that on Adobe Developer Connection you’ll find many resources to help you master mobile development.
Keep an eye on my blog too, because I’m planning more stuff on the mobile front.

No comments:

Post a Comment