IT

Flash Development for Android Cookbook.pdf

DownLoad Book

Published: 2018-03-17 Author:Bieber 26 Browses


Tags: flash development android

默认图片

书名: Flash Development for Android Cookbook

作者: Joseph Labrecque

副书名: Over 90 recipes to build exciting Android applications with Flash, Flex, and AIR

出版日期: June 2011

页数: 372

ISBN: 978-1-84969-142-0

Extracting password :e5585d1f77ac0656


Flash Development for
Android Cookbook
Over 90 recipes to build exciting Android applications with
Flash, Flex, and AIR
Joseph Labrecque
BIRMINGHAM - MUMBAI
Flash Development for Android Cookbook
Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the Joseph Labrecque, nor Packt Publishing,
and its dealers and distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2011
Production Reference: 1100611
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849691-42-0
www.packtpub.com
Cover Image by Ed Maclean (edmaclean@gmail.com)
Credits
Author
Joseph Labrecque
Reviewers
Fabio Biondi
Sean Moore
Leonardo Risuleo
Acquisition Editor
Wilson D'souza
Development Editor
Neha Mallik
Technical Editors
Shreerang Deshpande
Merwine Machado
Project Coordinator
Jovita Pinto
Proofreader
Aaron Nash
Indexer
Monica Ajmera
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy
Foreword
Mobile is as HOT as a Habanero Chili!
It's taken a few years, but mobile and devices are nally hot. How hot? Like biting into a
freshly ripe, raw, Habanero chili kind-a-HOT. Can you taste the virtual heat on your virtual
tongue yet?
Yowza! The point I'm trying to get across is this. The broader mobile and device industry
has nally gone mainstream. Why else would you be reading this right now? Intellectual
curiosity? Well, maybe, but I'm wagering much more likely, because you want to learn
about the amazing and wonderful world of mobile, today!
Yes, folks, I think you'll agree almost 100 percent that mobile is nally hip, cool, sleek,
and dare I say it: glitzy. Unless you been living in some proverbial cave for the last few
years, you know this for a fact! Like it or not, our modern societies now operate in a world
dominated with internet connected small-screen pocket-sized Smartphone, e-readers,
mid-screen sized Tablets, and large screen digital TVs, and countless other gadgets
and gizmos in all their bountiful and lavish form factors. In fact, with all these devices
and platforms, recently, it occurs to me as if we're all at some gigantic virtual party, and
there's one huge smorgasbord on the dinner table for developers to dig into. Of course,
I'm sure you'll agree the Android dish is one of the main courses you are eyeing to gobble
down, rst, right?
As an early adopter to the mobile industry, and one of the brave souls who pioneered
work with Flash and other early mobile technologies on various mobile and device
platforms over the years, it gives me great satisfaction to see what I had been advocating
has nally come to fruition. Yes! That proverbial egg timer has nally rung, and the apps
are ying out of the oven. Careful, boy are they RED HOT!
It strikes me that with all the excitement in developer kitchen these days, it feels a bit like
the explosive growth of the early days of the World Wide Web back in the 90's. There are
some changes now, though. One of the big changes now, is that we now have all these
form factors with various screens instead of those clunky desktop PCs and CRTs!
Smart phones and other devices have turned our cell phones into our pocket sized
computers. Yes, I said computers! Like it or not, for much of the modern world, our
personal computers of today, now t in our pockets, and they are part of our daily lives
and routines as we move through the world.
Mmmmmm...Yummy! Pocket-sized Android device treats for desert, anyone?!
Android with a dash of Flash
So, how does Adobe t into all this? Well, Adobe has been hard at work over the past
few years rening their suite of tools and products to help with the growing challenge
of allowing designers and developers to design, develop, and deploy compelling mobile
and device experiences, faster, better, and easier. There is no shortage of exciting and
compelling stream of news and innovations coming from Adobe's Engineering 'kitchen'
these days as I write this passage!
Adobe Flash, Flex, and AIR have been retooled, retrotted, and enhanced to make it
signicantly easier for existing Flash and Flex professionals to start leveraging Adobe
Creative Suite and other tools to target not only Android but also OS, BlackBerry Tablet
OS, and other mobile and device platforms soon to come. To me, the Flash Platform is
like a fork utensil. When it's appropriate, by all means use it to your advantage, especially
when trying to get food into your mouth!
The general idea of write once, tweak, and deploy to as many supported targets as
possible is a very real; and attainable goal when you look at what Adobe can provide
these days. Whether you're a long-time Flash veteran new to the mobile aspects
developing for Android, or whether you're a seasoned native Android developer curious
about the Flash Platform; you'll nd recipes to help quench your thirst and ll your belly.
All you have to do is give it a try and see the results!
This book will help you do that! So "What's Cooking" in this Book?
As a famous chef might say in his famous cooking shows in the US, "BAM"!
In this title, Joseph takes you through some recipes on how to leverage your existing Flash
and ActionScript skills to build for Android Platform. I have gotten the unique pleasure
of seeing some of the early material. Strap on your coding apron and get ready to bake
some code recipes very soon, my fellow readers!
In this title, Joseph will explain more than one hundred examples about how to dealing
with things like multi-touch and gesture input, accessing GPS and location features,
leveraging the accelerometer, as well as tying into audio and visual inputs such as
camera and microphone on mobile devices. He'll also cover working with media such as
images, video and audio, and handling device layout and scaling, plus more tasty morsels
of mobile development goodness using ActionScript for AIR using Flash and Flex based
mobile applications on the Android Platform. Although this 'cookbook' assumes you know
at least some ActionScript and Flash basics, most will be able to pick up much of the
code and start running with it, given it's in a nice, juicy, step by step, recipe style format.
You should be able to apply these code snacks to your favorite designer or developer
workow whether you're using Flash Builder, Flash IDE, or any other piece of popular
Flash authoring environment out there.
Well, are you hungry yet? Yes? Good! Well, time to get your inner-baker on, and cook
some ashy applications! After all, you have all those millions of hungry Android
consumers to feed with your tasty, nger licking good, creations. The oven is pre-heated,
now. Joseph's waiting for you in his coding kitchen. He's got lots of little snacks for you to
try out. Let's meet him in his kitchen and start cooking up some Android based recipes
using ActionScript, shall we?
P.S. Sorry if I made you physically hungry or thirsty while reading this foreword. Why not
grab a beer, or a red bull.
Also, why not put in that phone order in for pizza delivery? Now's the perfect time before
you dig in!
Bon Appétit and happy coding!
Scott Janousek,
Mobile and Device Technologist,
Gadget Geek and CEO/Founder of Hooken Mobile
About the Author
Joseph Labrecque is primarily employed by the University of Denver as a senior
interactive software developer specializing in the Adobe Flash Platform, where he
produces innovative academic toolsets for both traditional desktop environments and
emerging mobile spaces. Alongside this principal role, he often serves as adjunct faculty,
communicating upon a variety of Flash Platform solutions and general web design and
development subjects.
In addition to his accomplishments in higher education, Joseph is the proprietor of
Fractured Vision Media, LLC; a digital media production company, technical consultancy,
and distribution vehicle for his creative works. He is founder and sole abiding member of
the dark ambient recording project 'An Early Morning Letter, Displaced' whose releases
have received international award nominations and underground acclaim.
Joseph has contributed to a number of respected community publications as an article
writer and video tutorialist. He regularly speaks at user group meetings and industry
conferences such as Adobe MAX, FITC, and D2WC. In 2010, he received an Adobe Impact
Award in recognition of his outstanding contribution to the education community. He has
served as an Adobe Education Leader since 2008 and is also a 2011 Adobe
Community Professional.
Visit him on the web at http://memoryspiral.com/.
Special thanks to my wife Leslie, and to our daughters; Paige and Lily, for
bearing with me during the production of this work.
About the Reviewers
Fabio Biondi is a freelancer living in the north east of Italy. Since 2003 he deals almost
exclusively with the Adobe Flash Platform technologies.
He is an Adobe Certied Instructor (ACI) in Flex, AIR, Flash Professional, Flash Catalyst,
and FlashLite (ACE) and lately he has devoted time and resources to the development of
mobile and social networking applications.
Fabio runs a blog (www.fabiobiondi.com/blog) and a YouTube Channel
(http://www.youtube.com/user/BiondiFabio) where he provides free tutorials,
scripts, and news about the latest Adobe Flash Platform technologies.
I would like to thank my girlfriend Lisa, for always supporting and
encouraging me, and the Packt Publishing guys, Jovita and Wilson, for the
opportunity they have given to me.
Sean Moore has been developing web applications since 1998. He's been passionate
about Flash and ActionScript development for over eight years and working with Flex
for over four years. He was chosen to be a Flex Developer Community Champion and
an Adobe Community Professional by Adobe for his hard work and dedication to the
Flash Platform Community. Sean is a certied Flash developer and also a certied Flex
developer. Sean specializes in the development of Adobe AIR applications. He is the
creator of the ActionScript Cheatsheets. Sean has provided development and consulting
services for 2Advanced, Adobe Consulting, and Universal Mind. He's also worked with
many small businesses on Flash, Flex, and AIR applications. Sean has written Flex and
AIR articles for Adobe, O'Reilly, and Flash Magazine. He's provided technical authoring for
Manning Publications, Addison Wesley and O'Reilly. Sean has also given presentations at
various user groups on best practices for Flex development. Sean is also very interested
in BCI technology and Arduino development.
I'd like to thank the author for doing such a great job and also asking me to
be a technical reviewer.
Leonardo Risuleo is a designer and developer with several years experience in mobile,
new media and user experience. He's a highly dedicated professional and passionate
about what he does. He started back in 2003 and during these years he worked on a
variety of different mobile and embedded platforms for a number of well known brands.
Leo designs, prototypes, and develops mobile applications, games, widgets,
and websites.
Apart from being a Flash Platform enthusiast, Leo also contributes to the Flash and
mobile community as an author and blogger, and he's co-founder of the Italian 'Mobile &
Devices Adobe User Group'. From 2008 to 2010, Leo had the honor to be Forum Nokia
Champion—a recognition and reward program for top mobile developer worldwide.
In 2010 he formally founded Small Screen Design, a design and development studio
focused on mobile design and user experience.
www.PacktPub.com
Support les, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support les and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub les
available? You can upgrade to the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@
packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
f Fully searchable across every book published by Packt
f Copy and paste, print and bookmark content
f On demand and accessible via web browser
Free Access for Packt account hold-
ers
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.
Instant Updates on New Packt Books
Get notied! Find out when new books are published by following @PacktEnterprise on
Twitter, or the Packt Enterprise Facebook page.
Table of Contents
Preface 1
Chapter 1: Getting Ready to Work with Android: Development
Environment and Project Setup 7
Introduction 8
Using Flash Professional CS5.5 to develop Android applications 8
Targeting AIR for Android with Flash Professional CS5.5 10
Using Flash Builder 4.5 to develop Android applications 13
Enabling Flash Builder 4 or Flex Builder to access Flex Mobile SDKs 15
Using Flash Builder 4 and below to develop Android applications 18
Enabling Powerasher FDT 4.1 to access Flex Mobile SDKs 21
Using Powerasher FDT 4.1 and below to develop Android applications 23
Converting a standard Flex project to a Flex Mobile project 26
Conguring the AIR SDK to package AIR for Android applications on Windows 29
Conguring the AIR SDK to package AIR for Android applications on
Linux or Mac OS 30
Chapter 2: Interaction Experience: Multitouch, Gestures, and Other Input 33
Introduction 34
Detecting supported device input types 34
Detecting whether or not a device supports multitouch 36
Verifying specic gesture support for common interactions 38
Using gestures to zoom a display object 41
Using gestures to pan a display object 43
Using gestures to swipe a display object 46
Using gestures to rotate a display object 49
Accessing raw touchpoint data 52
Creating a custom gesture based upon touchPoint data 55
Emulating the Android long-press interaction 59
ii
Table of Contents
Invoking the virtual keyboard programmatically 62
Responding to Android soft-key interactions 66
Responding to trackball and D-Pad events 68
Chapter 3: Movement through Space: Accelerometer and
Geolocation Sensors 73
Introduction 74
Detecting whether or not an Android device supports the accelerometer 74
Detecting Android device movement in 3D space 76
Adjusting the accelerometer sensor update interval 78
Updating display object position through accelerometer events 82
Switching between portrait and landscape based upon device tilt 86
Detecting whether or not a device supports a geolocation sensor 89
Retrieving device geolocation sensor data 93
Adjusting the geolocation sensor update interval 96
Retrieving map data through geolocation coordinates 101
Chapter 4: Visual and Audio Input: Camera and Microphone Access 107
Introduction 107
Detecting camera and microphone support 108
Using the traditional camera API to save a captured image 110
Using the Mobile CameraUI API to save a captured photograph 113
Using the Mobile CameraUI API to save a captured video 118
Using the device microphone to monitor audio sample data 122
Recording Microphone Audio Sample Data 125
Chapter 5: Rich Media Presentation: Working with Images,
Video, and Audio 131
Introduction 131
Loading photographs from the device cameraRoll 132
Applying Pixel Bender Shader effects to loaded images 136
Playing video les from the local lesystem or over HTTP 141
Playing remote video streams over RTMP 146
Playing audio les from the local lesystem or over HTTP 152
Generating an audio spectrum visualizer 156
Generating audio tones for your application 159
Chapter 6: Structural Adaptation: Handling Device Layout and Scaling 163
Introduction 164
Detecting useable screen bounds and resolution 164
Detecting screen orientation changes 166
Scaling visual elements across devices at runtime 169
Scaling visual elements based on stage resize in Flash Professional CS5.5 172
iii
Table of Contents
Employing the Project panel in Flash Professional CS5.5 176
Freezing a Flex application to landscape or portrait mode 179
Dening a blank Flex mobile application 183
Dening a Flex mobile view-based application 185
Dening a Flex mobile tabbed application with multiple sections 188
Using a splash screen within a Flex mobile application 191
Conguring the ActionBar within a Flex mobile project for use with
ViewNavigator 194
Hiding the ActionBar control in a single view for a Flex mobile project 198
Chapter 7: Native Interaction: StageWebView and URI Handlers 201
Introduction 201
Opening a website in the default Android browser 202
Rendering a website within an application 205
Managing the StageWebView history 210
Using StageWebView to load ads using ActionScript 216
Using StageWebView to load ads within a Flex mobile project 219
Making a phone call from an application 225
Sending a text message from an application 228
Invoking Google maps from an application 231
Invoking the Android Market using application URIs 236
Sending e-mail from an application 239
Chapter 8: Abundant Access: File System and Local Database 243
Introduction 243
Opening a local le from device storage 244
Saving a le to device storage 247
Saving data across sessions through local shared object 252
Storing application state automatically by using Flex 257
Creating a local SQLite database 260
Providing a default application database 266
Automating database tasks with FlexORM 271
Chapter 9: Manifest Assurance: Security and Android Permissions 279
Introduction 279
Setting application permissions with the Android Manifest le 280
Preventing the device screen from dimming 283
Establishing Android custom URI schemes 286
Anticipating Android Compatibility Filtering 290
Instructing an application to be installed to Device SDCard 292
Encrypting a local SQLite database 294
iv
Table of Contents
Chapter 10: Avoiding Problems: Debugging and Resource
Considerations 301
Introduction 301
Debugging an application with Flash Professional 302
Debugging an application with Flash Builder 305
Rendering application elements using the device GPU 310
Automating application shutdown upon device interruption events 311
Exiting your application with the device back button 313
Monitoring memory usage and frame rate in an application 314
Chapter 11: Final Considerations: Application Compilation and
Distribution 319
Introduction 320
Generating a code-signing certicate using Flash Professional 320
Generating a code-signing certicate using Flash Builder 322
Generating a code-signing certicate using FDT 323
Generating a code-signing certicate using the AIR Developer Tool 325
Preparing icon les for distribution 327
Compiling an application using Flash Professional 330
Compiling an application using Flash Builder 334
Compiling an application when using FDT 336
Compiling an application using the AIR Developer Tool 337
Submitting an application to the Android Market 339
Index 343
Preface
With the ongoing explosion of the mobile Android operating system and proliferation of
Android powered devices in the smart phone and tablet computing markets, this is the perfect
time to explore the world of Android development using the Flash Platform. Adobe recently
released statistics announcing that by the end of 2011, it is projected that more than 200
million smartphones and tablets will support Adobe AIR applications. For 2011, the company
expects the mobile Flash Player to be supported on more than 132 million units worldwide.
This book provides a variety of fundamental recipes exploring common needs of the mobile
Android developer when utilizing these Flash Platform runtimes.
Many existing Flash application developers are excited with the prospect of building mobile
applications for Android devices, but where to begin? Expand your reach into mobile
application development by using this text as a guide. When possible, the recipes in this book
are written using pure ActionScript 3, allowing the reader to work through each example in
the tool of their choice. In some instances, we demonstrate the power and exibility of the
mobile Flex framework when dealing with specic layout and structural needs. Jump-start your
experience with mobile Android through the step-by-step examples found within.
Flash Development for Android Cookbook will demonstrate a wide variety of mobile-specic
examples specically conceived to be direct and useful in the development of applications
for Android devices. Everything you need to get started is included along with suggestions
to further your experience with Flash, Flex, and AIR when developing mobile Android
applications.
Topics covered within this book include development environment conguration, mobile
project creation and conversion, the use of touch and gestures, responding to changes in
location and device movement in 3D space, the capture, generation, and manipulation of
images, video and audio, application layout and structure, tapping into native processes and
hardware, and the manipulation of the le system and managing local application databases.
The book will also cover things such as Android-specic device permissions, application
optimization techniques, and the packaging and distribution options available on the mobile
Android platform.
Preface
2
What this book covers
Chapter 1, Getting Ready to Work with Android: Development Environment and Project Setup,
demonstrates the conguration of a number of development environments and tools which
can be used in developing Flash content for mobile Android.
Chapter 2, Interaction Experience: Multitouch, Gestures, and Other Input, informs the reader
with a variety of unique touch and gesture interactions that can be used across Flash Platform
runtimes.
Chapter 3, Movement through Space: Accelerometer and Geolocation Sensors, empowers
your applications with the ability to pinpoint a user's precise geographic location and even
determine local changes in device shift and tilt through the on-board accelerometer.
Chapter 4, Visual and Audio Input: Camera and Microphone Access, discusses how to capture
still images, video, and audio from integrated device hardware through both Flash based
capture methods and while employing native camera applications.
Chapter 5, Rich Media Presentation: Working with Images, Video, and Audio, takes a look at
a variety of media presentation mechanisms available to us on the Flash Platform including
playback of progressive and streaming video, the use of Pixel Bender shaders, and even audio
generation.
Chapter 6, Structural Adaptation: Handling Device Layout and Scaling, discusses a variety of
methods we can use to gain detailed information regarding device displays, and the usage of
this data when sizing and positioning visual elements along with structured layout through the
mobile Flex framework.
Chapter 7, Native Interaction: Stage WebView and URI Handlers, demonstrates methods of
utilizing native applications such as the Web browser, e-mail, SMS, Telephone, and Maps as
extensions of our Flash based experience.
Chapter 8, Abundant Access: File System and Local Database, provides the readers with
details of the steps necessary to access, open and write to le streams on the device storage,
create and manage local SQLite databases, and preserve application state upon application
interruption.
Chapter 9, Manifest Assurance: Security and Android Permissions, demonstrates the various
Android Manifest permissions and provides examples of Market ltering, encrypted database
support, and other security-minded techniques.
Chapter 10, Avoiding Problems: Debugging and Resource Considerations, looks at ways in
which a developer can streamline the efciency of an application by tapping into the device
GPU, handling user interaction in responsible ways, and memory management techniques.
Preface
3
Chapter 11, Final Considerations: Application Compilation and Distribution, advises the
reader on project preparation, code signing, release compilation, and distribution through the
global Android Market.
What you need for this book
To make use of the recipes included in this book, you need access to software for developing
Android applications with the Flash Platform. We recommend using Adobe Flash Builder
4.5, Adobe Flash Professional CS5.5, or PowerFlasher FDT 4.2 and above. These Integrated
Development Environments are preferred because of their specic support of a mobile
Android workow, but you may actually use any application you prefer to write code that will be
compiled for AIR for Android and deployed to mobile devices.
You will, however, need access to the following (if not using these particular IDEs):
f Adobe AIR SDK – for compiling your Flash applications to .APK for Android
f Flex 4.5 SDK – if you want to take advantage of the mobile Flex framework
The Adobe AIR SDK is included with both Flash Professional CS5.5 and Flash Builder 4.5.
The Flex 4.5 SDK is included with Flash Builder 4.5. If using alternative software to develop
Flash based Android applications, these SDKs can be downloaded freely from the Adobe open
source website.
You will also want to be sure to have access to a device running Android 2.2 or above with
AIR for Android 2.5 or above installed for demonstrating the recipes, and testing your
own applications.
Who this book is for
This book contains recipes covering a variety of topics from the very simple, to those which
are more advanced. If you are a seasoned Flash developer, this book will get you quickly up
to speed with what is possible with Android. For those who are new to Flash, welcome to the
world of visual rich, rapid application development for mobile Android devices! If you have any
interest in Flash development for Android, this book has you covered.
Preface
4
Conventions
In this book, you will nd a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Create a new le called recipe1.py to put all of
this recipe's code."
A block of code is set as follows:
streamClient = new Object();
streamClient.onBWDone = onTextData;
streamClient.onTextData = onTextData;
streamClient.onMetaData = onMetaData;
streamClient.onCuePoint = onCuePoint;
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "There are many choices of
IDE (Integrated Development Environment) for developing Flash platform projects for
Android devices".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really get the most out of.
To send us general feedback, simply send an e-mail to feedback@packtpub.com, and
mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the
SUGGEST A TITLE form on www.packtpub.com or e-mail suggest@packtpub.com.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.
Preface
5
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.
Downloading the example code
You can download the example code les for all Packt books you have purchased from your
account at http://www.PacktPub.com. If you purchased this book elsewhere, you can
visit http://www.PacktPub.com/support and register to have the les e-mailed directly
to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you nd a mistake in one of our books—maybe a mistake in the text or the code—
we would be grateful if you would report this to us. By doing so, you can save other readers
from frustration and help us improve subsequent versions of this book. If you nd any errata,
please report them by visiting http://www.packtpub.com/support, selecting your book,
clicking on the errata submission form link, and entering the details of your errata. Once
your errata are veried, your submission will be accepted and the errata will be uploaded on
our website, or added to any list of existing errata, under the Errata section of that title. Any
existing errata can be viewed by selecting your title from http://www.packtpub.com/
support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.
Please contact us at copyright@packtpub.com with a link to the suspected pirated
material.
We appreciate your help in protecting our authors, and our ability to bring you valuable
content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with any
aspect of the book, and we will do our best to address it.
1
Getting Ready to
Work with Android:
Development
Environment and
Project Setup
This chapter will cover the following recipes:
f Using Flash Professional CS5.5 to develop Android applications
f Targeting AIR for Android with Flash Professional CS5.5
f Using Flash Builder 4.5 to develop Android applications
f Enabling Flash Builder 4 or Flex Builder to access Flex Mobile SDKs
f Using Flash Builder 4 and below to develop Android applications
f Using Powerasher FDT 4.2 to develop Android applications
f Enabling Powerasher FDT 4.1 to access Flex Mobile SDKs
f Using Powerasher FDT 4.1 and below to develop Android applications
f Converting a Standard Flex project to a Flex Mobile project
f Conguring the AIR SDK to Package AIR for Android applications on Windows
f Conguring the AIR SDK to Package AIR for Android Applications on Linux or Mac OS
Getting Ready to Work with Android: Development Environment and Project Setup
8
Introduction
There are many choices of IDE (Integrated Development Environment) for developing Flash
platform projects for Android devices. We will focus on a few of the most popular: Adobe
Flash Professional, Adobe Flash Builder, and Powerasher FDT. This chapter will include
recipes geared to getting a new Android project started in each IDE, and making the most of
what is available with regard to workow and toolsets. You will learn how to congure each
environment in order to develop for the Android operating system.
Flash Builder and FDT, along with the Flex framework have the most to offer for Android
development as there is a streamlined workow, set of controls, and containers available
especially for the development of mobile Android projects using Adobe AIR for Android as a
development platform.
Flash Professional provides some workow tools, but the main benet lies in potential
familiarity with the environment, and the generation of projects not tied to the Flex framework.
This IDE is often used for game development because of its open nature.
For the purists or users of alternative IDEs, it is also possible to generate Android applications
through a command line interface using the free AIR SDK tools.
Using Flash Professional CS5.5 to develop
Android applications
Flash Professional is a good choice for building Android applications that are more lightweight
than their Flex-based counterparts. There is not as robust a workow in the case of Flash
Professional when compared to what is included with an IDE such as Flash Builder, but
depending upon the application being developed, it may be the better tool for the job.
Flash Professional CS5.5 includes everything needed to target Android already baked in!
How to do it…
Setting up an AIR for Android project in Flash Professional CS5.5 is very direct:
1. We will rst create a new project by choosing AIR for Android under the Create New
section of the Flash Professional welcome screen:
Chapter 1
9
2. We can then verify that we are targeting AIR for Android by taking a look at the
document properties under the Properties panel:
Getting Ready to Work with Android: Development Environment and Project Setup
10
3. We can also modify existing Flash documents to target Android by selecting AIR for
Android as the Player option.
4. Now, simply build your Flash project as you normally would. Adobe has made the
process of targeting Android with Flash Professional CS5.5 absolutely painless.
How it works…
With Flash Professional CS5.5, we have more compiler options available to us than ever
before. Taking the steps outlined in the preceding section will ensure that your project is
capable of targeting AIR for Android in place of the desktop Flash Player or AIR for desktop by
adding a number of Android-specic compiler options to our publish settings.
There's more…
If developing for the mobile Flash Player for Android, we will not need to congure anything
for the AIR runtime. To target Flash Player, we must simply keep in mind the limitations and
differences inherent to mobile Android devices.
Targeting AIR for Android with Flash
Professional CS5.5
Flash Professional is a good choice for building Android applications that are more lightweight
than their Flex-based counterparts. There is not as robust a workow in the case of Flash
Professional when compared to what is included with an IDE such as Flash Builder, but
depending upon the application being developed; it may be the better tool for the job.
How to do it…
There are two ways of targeting AIR for Android with Flash Professional:
1. Firstly, create a new project by choosing AIR for Android under the Create from
Template section of the Flash Professional welcome screen:
Chapter 1
11
2. This will present a choice of several templates targeting AIR for Android. Choose the
appropriate template for your device:
Getting Ready to Work with Android: Development Environment and Project Setup
12
3. Alternatively, create a new ActionScript 3.0 project and open your publish settings by
going to File | Publish Settings.
4. This will open a dialog allowing you to choose your target platform. In this case, we
want to select AIR Android as the appropriate Player:
5. Now you will be able to adjust Application and Installer Settings targeting Android,
and compile projects into .apk les.
How it works…
With recent versions of Flash Professional, we have more compiler options available to us
than ever before. Taking the stepsoutlined abovewill ensure that your project is capable of
targeting AIR for Android in place of the desktop Flash Player or AIR for desktop by adding a
number of Android-specic compiler options to our publish settings.
There's more…
If developing for the mobile Flash Player for Android, we will not need to congure anything
for the AIR runtime. To target Flash Player, we must simply keep in mind the limitations and
differences inherent to mobile Android devices.
See also…
For more information about compiling AIR for Android applications with Flash Professional,
you will want to refer to Chapter 11, Final Considerations: Application Compilation
and Distribution
Chapter 1
13
Using Flash Builder 4.5 to develop Android
applications
Flash Builder 4.5 already comes equipped with everything, we need to begin developing
mobile applications using either ActionScript or the mobile Flex Framework. For those
unfamiliar with the differences between ActionScript and Flex, basically, the Flex framework
provides a set of components, layouts, and data control that is precongured for building
Flash applications, whereas when using ActionScript by itself, everything must be written
from scratch. Flex 4.5 includes mobile features such as optimized component skins to
run very well on devices, a new ViewNavigator application type, which is tailored to the
mobile experience, and includes support for touch and gestures across the mobile-optimized
component set.
How to do it…
In place of a normal ActionScript project or Flex project, we must specically create either an
ActionScript Mobile project or Flex Mobile project:
1. In the Flash Builder Package Explorer, right-click on some empty space and choose
New | Flex Mobile Project or New | ActionScript Mobile Project:
Getting Ready to Work with Android: Development Environment and Project Setup
14
2. We will then provide the mobile project with a name and choose where Flash Builder
should store the project les on the local machine.
3. The next step allows us to choose the target platform, in this case, Google Android,
and dene which application template to use (if you are making use of the mobile
Flex framework). We can also set the default View name on this screen through the
Initial view title input..
4. Additionally, we will choose whether or not the application will reorient based upon
device tilt with the Automatically reorient option. We can select to display the
application at full screen by selecting the Full screen checkbox.
5. One last selection to make on this screen is whether we would like to use density
aware skins in our mobile components by selecting the Automatically scale
application for different screen densities checkbox and selecting the appropriate
Application DPI setting.
Chapter 1
15
6. The rest of the project setup is really the same as any other project in Flash Builder.
How it works…
The choices we make when setting up a new project in Flash Builder determine which libraries
are imported, and used in an application. Dening a mobile application will not only include
specic component skins targeted to mobile, but will also restrict us from using components,
which are inappropriate for such use. We will also have full access to mobile-specic
application structures such as the mobile ViewNavigator, ActionBar, or TabBar. These
additions to the mobile Flex framework can be used to greatly speed up the development
of stateful mobile Android applications, as they deal with application structure, navigation
controls, and layout.
See also…
You can actually use previous versions of Flash Builder to compile AIR for Android
applications. Check out the next recipe, Enabling Flash Builder 4 or Flex Builder to access Flex
Mobile SDKs for an example of this.
Enabling Flash Builder 4 or Flex Builder to
access Flex Mobile SDKs
You don't necessarily need to have the latest version of Flash Builder to write applications
for Android. This recipe will demonstrate how to integrate the latest Flex SDK into an older
version of Flash Builder (or even Flex Builder) to take advantage of the mobile framework
improvements.
Even though we will be able to use the new component sets and streamlined
structure for Android, many of the workow enhancements such as support
for a new mobile application view structure, optimized component skins with
touch and gesture support, and other niceties found in newer versions of
Flash Builder simply will not exist and we will have to compile the application
for distribution using the AIR SDK and command line tools.
How to do it…
The following steps are used for getting an older version of Flash Builder congured for
Android development:
1. Visit the Adobe Open Source website at http://opensource.adobe.com/ and
locate the latest build of the Flex SDK.
收藏
分享
暂无回复
Author