Professional Flash Mobile Development
Total Page:16
File Type:pdf, Size:1020Kb
PROFESSIONAL FLASH MOBILE DEVELOPMENT I NTRODUCTION . xv. ⊲ PART I GETTING STARTED CHAPTER 1 Introducing Flash Development for Mobile Devices . 3 CHAPTER 2 Setting Up Your Development Environment . .13 CHAPTER 3 Building and Installing VanillaApp . 39 ⊲ PART II TOUCH AND USER INTERACTION CHAPTER 4 Rethinking ActionScript Programming . 77 CHAPTER 5 Multitouch API . 87 CHAPTER 6 Detecting Motion with Accelerometer . 109 CHAPTER 7 Implementing Auto Orientation . 129 CHAPTER 8 Geolocation API . 145 CHAPTER 9 Service Integration Using URL Protocols . 179 CA H PTER 10 Android Camera, Camera Roll, and Microphone . .209 ⊲ PART III DATA CHAPTER 11 File Management . 23. 7 CHAPTER 12 Local Databases . 25. 5 ⊲ PART IV TESTING AND DEBUggING CHAPTER 13 Remote Debugging . 27. 3 CHAPTER 14 Submitting Your App to the App Store . 279 AppN E DIX A Application Descriptor Settings . 291 AppN E DIX B Compiling Applications from the Command Line . 305. IXNDE . 309 ProfessioNal Flash® Mobile Development CREATING ANDROID™ aND IPHONE® AppLICATIONS Richard Wagner Professional Flash® Mobile Development: Creating Android™ and iPhone® Applications Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-62007-6 ISBN: 978-1-118-03731-7 (ebk) ISBN: 978-1-118-03732-4 (ebk) ISBN: 978-1-118-03733-1 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro- motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the pub- lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2010926881 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other coun- tries, and may not be used without written permission. Flash is a registered trademark of Adobe Systems, Inc. Android is a trademark of Google, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. To Kimberly and the boys. CREDITS EXECUTIVE EdITOR VICE PRESIDENT AND EXECUTIVE GROUP Carol Long PUBLISHER Richard Swadley PROJECT EdITOR Sydney Jones Argenta VICE PRESIDENT AND EXECUTIVE PUBLISHER Barry Pruett TECHNICAL EdITORS Drew Falkman ASSOCIATE PUBLISHER Jim Minatel PRODUCTION EdITOR Rebecca Anderson PROJECT COORDINATOR, COVER Katie Crocker COPY EdITOR Karen Gill COmpOSITOR Jeff Lytle, EdITORIAL DIRECTOR Happenstance Type-O-Rama Robyn B . Siesky PROOFREADER EdITORIAL MANAGER Nancy Carrasco Mary Beth Wakefield INDEXER FREELANCER EdITORIAL MANAGER Robert Swanson Rosemarie Graham COVER DESIGNER MARKETING MANAGER Michael E . Trent Ashley Zurcher COVER ImAGE PRODUCTION MANAGER © Hedda Gjerpen/istockphoto com. Tim Tate ABOUT THE AUTHOR RICHARD WAGNER is Lead Product Architect, Web/Mobile at MAARK and author of several Web- and mobile-related books, including Safari and WebKit Development for iPhone OS 3.0, XSLT For Dummies, Creating Web Pages All-In-One Desk Reference For Dummies, Web Design Before & After Makeovers, and more. Richard has also authored several books outside of the field of technol- ogy, including The Myth of Happiness and The Expeditionary Man. ABOUT THE TECHNICAL EdITOR DREW FALKMAN has been developing web applications since it was standard practice to test for Mosaic and Netscape. He rode the dot-com wave through growing a startup and achieving venture funding, and he is now happy to consult and train through his own company, Falkon Productions. Over the years, he has architected and worked on sites for customers from startup cattle auctions to Fortune 500 companies using a host of technologies including Java, ColdFusion, JavaScript, Adobe Flex/Flash, PHP, and WordPress. Also a writer, Drew has authored two books on Java for Adobe Press and done technical editing for Que Publishing and Wiley. He has been published in developers’ journals and online, including on Adobe.com. He is an Adobe Certified Instructor and Developer and has spoken at conferences around the U.S. He currently resides in Santa Monica, CA. A CKNOWLEdgmENTS T HIS WRITING OF THIS BOOK has reflected the stormy seas that Adobe has battled in order to release Flash and Adobe AIR for mobile platforms. It started off as an iPhone-based book for Flash develop- ers until Apple infamously changed its terms of use to exclude Packager for iPhone as being a valid way to create iPhone apps. So, we shifted course, transforming the book into an Android-focused book. However, when I was about 80 percent done with the writing, Apple changed its restrictive policy on Packager for iPhone, opening up Flash development once again to the iOS platform. In response, we changed the focus of the book yet again to account for both Android and iOS devices. On this stormy, but amazing adventure, I was blessed with as good of an editorial team as I have ever had. Major kudos to Sydney Jones Argenta who was project editor. Sydney was diligent, kept me on track, and always kept things positive and forward-thinking. Also thanks to Drew Falkman for his close attention to the technical details as well as many suggestions that improved the quality of the book. Finally, thanks also to Karen Gill for her editing prowess. It was a joy working with this amazing group of editors. CONTENTS INTRODUCTION xv PART I: GETTING STARTED CHAPTER 1: INTRODUCING FLASH DEVELOpmENT FOR MOBILE DEVICES 3 Expanding to the Mobile World 3 Discovering Adobe AIR 5 Building for Android 5 Building for iOS 6 What You Can and Cannot Do 7 Device Support 7 Unsupported AS3 API Objects 8 Understanding the AIR for Android Security Model 9 Getting to Know the Android SDK 10 Getting to Know the iOS SDK 11 Summary 11 CHAPTER 2: SETTING Up YOUR DEVELOpmENT ENVIRONMENT 13 Preparing for Android Development 13 Installing the AIR SDK 13 Creating a Code-Signing Certificate 15 Installing the Flash CS5 Extension for AIR 2 .5 17 Installing the Android SDK 17 Adding the Android SDK to Your System Path 19 Creating an Android Virtual Device 21 Installing the AIR Runtime onto Your Device 22 Comparing the Development Environment Options 22 Using MXML in Android Apps 23 Preparing for iOS Development 23 Joining the iPhone Developer Program 23 Getting an iPhone Developer Certificate 24 Retrieving the Developer Certificate 28 Adding a Device 30 Creating an App ID 31 CONTENTS Creating a Provisioning Profile 32 Installing the Provisioning Profile 35 Summary 37 CHAPTER 3: BUILDING AND INSTALLING VANILLAApp 39 VanillaApp for Android 39 Creating a Project 40 Creating a Flash Document for AIR for Android 40 Creating an ActionScript Document Class 41 Coding the Document Class 43 Adding Icons 49 Defining Android Settings 49 Previewing the App inside Flash 52 Publishing and Installing the Application 53 Running the App on an Android Device 53 VanillaApp for iOS 54 Creating a Project 56 Creating an iPhone-Based Flash Document 57 Creating an ActionScript Document Class 57 Coding the Document Class 58 Creating a Splash Screen 65 Adding Icons 66 Defining iPhone Settings 66 Previewing the App inside Flash 70 Publishing the Application 70 Installing the App on an