39,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 361
Veröffentlichungsjahr: 2011
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 (<[email protected]>)
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
It's taken a few years, but mobile and devices are finally 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 finally 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 finally 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, first, 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 finally come to fruition. Yes! That proverbial egg timer has finally rung, and the apps are flying 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 fit 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?!
So, how does Adobe fit into all this? Well, Adobe has been hard at work over the past few years refining 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, retrofitted, and enhanced to make it significantly 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 find recipes to help quench your thirst and fill 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 workflow 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 flashy applications! After all, you have all those millions of hungry Android consumers to feed with your tasty, finger 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
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.
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 Certified 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 certified Flash developer and also a certified 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.
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files 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 <[email protected]> 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.
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.
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter, or the Packt Enterprise Facebook page.
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 flexibility of the mobile Flex framework when dealing with specific 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-specific examples specifically 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 configuration, 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 file system and managing local application databases. The book will also cover things such as Android-specific device permissions, application optimization techniques, and the packaging and distribution options available on the mobile Android platform.
Chapter 1, Getting Ready to Work with Android: Development Environment and Project Setup, demonstrates the configuration 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 file 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 filtering, 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 efficiency of an application by tapping into the device GPU, handling user interaction in responsible ways, and memory management techniques.
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.
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 specific support of a mobile Android workflow, 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):
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.
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.
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 <[email protected]>, 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 <[email protected]>.
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.
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.
You can download the example code files 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 files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find 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 find 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 verified, 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 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 <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
This chapter will cover the following recipes:
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 Powerflasher 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 workflow and toolsets. You will learn how to configure 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 workflow, 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 workflow tools, but the main benefit 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.
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 workflow 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!
Setting up an AIR for Android project in Flash Professional CS5.5 is very direct:
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-specific compiler options to our publish settings.
If developing for the mobile Flash Player for Android, we will not need to configure anything for the AIR runtime. To target Flash Player, we must simply keep in mind the limitations and differences inherent to mobile Android devices.
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 workflow 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.
There are two ways of targeting AIR for Android with Flash Professional:
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-specific compiler options to our publish settings.
If developing for the mobile Flash Player for Android, we will not need to configure anything for the AIR runtime. To target Flash Player, we must simply keep in mind the limitations and differences inherent to mobile Android devices.
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
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 preconfigured 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.
In place of a normal ActionScript project or Flex project, we must specifically create either an ActionScript Mobile project or Flex Mobile project:
The choices we make when setting up a new project in Flash Builder determine which libraries are imported, and used in an application. Defining a mobile application will not only include specific 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-specific 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.
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.