Book Image

Flash Development for Android Cookbook

By : Joseph Labrecque
Book Image

Flash Development for Android Cookbook

By: Joseph Labrecque

Overview of this book

Flash has now arrived to Android — the fastest growing smartphone platform. This offers massive opportunities for Flash developers who want to get into mobile development. At the same time, working on smartphones will introduce new challenges and issues that Flash developers may not be familiar with. The Flash Development for Android Cookbook enables Flash developers to branch out into Android mobile applications through a set of essential, easily demonstrable recipes. It takes you through the entire development workflow: from setting up a local development environment, to developing and testing your application, to compiling for distribution to the ever-growing Android Market. The Flash Development for Android Cookbook starts off with recipes that cover development environment configuration as well as mobile project creation and conversion. It then moves on to exciting topics such as the use of touch and gestures, responding to device movement in 3D space, working with multimedia, and handling application layout. Essential tasks such as tapping into native processes and manipulating the file system are also covered. We then move on to some cool advanced stuff such as Android-specific device permissions, application debugging and optimization techniques, and the packaging and distribution options available on the mobile Android platform. In a nutshell, this cookbook enables you to get quickly up to speed with mobile Android development using the Flash Platform in ways that are meaningful and immediately applicable to the rapidly growing area of mobile application development.
Table of Contents (18 chapters)
Flash Development for Android Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface

Using Flash Builder 4 and below to develop Android applications


To develop mobile Android application in Flash Builder 4, we will need to configure Flash Builder to enable access to a mobile Flex SDK. See the previous recipe if you have not yet configured Flash Builder or Flex Builder in this manner.

How to do it…

There is no specific mobile workflow or tooling built into versions of Flash Builder prior to Flash Builder 4.5. By taking the following steps, we can ensure that our project will be mobile-compatible:

  1. 1. In Flash Builder, right-click in the Package Explorer panel and choose New | Flex Project. Alternatively, we can choose ActionScript Project, but this will not include any mobile benefits, as the actual Flex SDK components will not be employed. However, it is useful to note that ActionScript projects will generally perform better than their Flex counterparts simply due to the fact that they do not rely on such a heavy framework.

  2. 2. The New Flex Project dialog will appear in which you must provide a Project name, and select whether to create the project targeting Web or Desktop. If this project will be compiled for AIR for Android, we will want to make sure to choose Desktop, as this application type will target the Adobe AIR runtime. If creating a project targeting Flash Player in the browser, we will choose Web.

  3. 3. When choosing Desktop, we will also want to be sure to choose a mobile-enhanced version of the Flex SDK for our Android project. Flex 4.5 and above include everything we need to begin developing robust Android applications.

  4. 4. The last thing we must do is make sure that the mobile-enabled Flex SWCs are going to be used in our project. In order to declare <s:ViewNavigatorApplication> or <s:TabbedViewNavigatorApplication> for the main container of our project, these specific SWCs must be accessible, else Flash Builder will report errors.

  5. 5. The final section of the New Flex Project dialog allows us to be sure the mobile SWCs are included. You will notice that mobilecomponents.swc is not included in our project. Select the tab labeled Library path and click on the button labeled Add SWC…:

  6. 6. When the Add SWC dialog appears, browse to the location of the selected Flex SDK. Assuming we unpackaged the SDK to C:\SDKs\Flex4 we will now browse to C:\SDKs\Flex\frameworks\libs\mobile select the mobilecomponents.swc file, and click on Open. This will add support for the mobile components to our application.

  7. 7. Complete the project setup. We are now able to use mobile specific containers and controls without receiving errors from Flash Builder, but we must make a few more adjustments in order to correctly compile our application.

  8. 8. Locate the AIR descriptor file in your project. It is normally named something like {MyProject}-app.xml and resides at the project root. Open this file and change the <visible> attribute to true. It may be necessary to uncomment this node, if it has been commented out.

  9. 9. Right-click on your project in the Package Explorer and select Properties.

  10. 10. Select the Flex Compiler menu option and add the following to the Additional compiler arguments: theme=C:\{SDK Location}\frameworks\themes\Mobile\mobile.swc

  11. 11. Finally, switch the root node of your main application file from <s:Application> to <s:ViewNavigatorApplication>. We can now author and compile applications using the mobile flex framework components.

How it works…

When specifying which type of project we want to create in Flash Builder, the IDE automatically makes available certain portions of the Flex framework so that we can work with all the components necessary for our project. Flash Builder 4 and earlier do not ship with any mobile-enabled Flex SDK and do not provide a workflow for Android projects. Because of this, we must explicitly tell Flash Builder to make use of these extra framework components.

The application descriptor file mentioned in the steps in the preceding section is used to configure an AIR application in various ways: setting the initial window properties, chrome attributes, and even system icons.

See also…

It is important to note that versions of Flash Builder prior to Flash Builder 4.5 will not include the ability to compile projects to .APK (the Android application file extension) and you will need to compile your project using the freely available AIR SDK. See Chapter 11 for information on how to do this.

It is also worth a mention that while you can develop your applications for Android using older versions of Flash Builder, you will not receive many of the benefits provided by a newer release, such as code completion.