Flash®, Flex®, and Air® Development for Mobile Devices
Total Page:16
File Type:pdf, Size:1020Kb
ffirs.indd ii 12/09/11 7:52 PM BEGINNING FLASH®, FLEX®, AND AIR® DEVELOPMENT FOR MOBILE DEVICES INTRODUCTION . xxi CHAPTER 1 An Introduction to Flash, Flex, and AIR . .1 CHAPTER 2 Getting Started . 35 CHAPTER 3 Building AIR Applications for Android, BlackBerry, and iOS Devices . 67 CHAPTER 4 Touch, Multitouch, and Gestures . .101 CHAPTER 5 Developing for Multiple Screen Sizes . 131 CHAPTER 6 Debugging Applications . .177 CHAPTER 7 Working with the Filesystem . 199 CHAPTER 8 Working with Data . 239 CHAPTER 9 Working with Audio and Video . 289 CHAPTER 10 Utilizing Device Features . 315 INDEX . 359 ffirs.indd i 12/09/11 7:52 PM ffirs.indd ii 12/09/11 7:52 PM BEGINNING Flash®, Flex®, and AIR® Development for Mobile Devices ffirs.indd iii 12/09/11 7:52 PM ffirs.indd iv 12/09/11 7:52 PM BEGINNING Flash®, Flex®, and AIR® Development for Mobile Devices Jermaine G. Anderson John Wiley & Sons, Inc. ffirs.indd v 12/09/11 7:52 PM Beginning Flash®, Flex®, and AIR® Development for Mobile Devices Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-94815-6 ISBN: 978-1-118-19334-1 (ebk) ISBN: 978-1-118-19335-8 (ebk) ISBN: 978-1-118-19336-5 (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 specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional 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 publisher 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 and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com. For more information about Wiley products, visit us at www.wiley.com. Library of Congress Control Number: 2011905204 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 affi liates, in the United States and other countries, and may not be used without written permission. Flash, Flex, and AIR are registered trademarks of Adobe Systems, Incorporated. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. ffirs.indd vi 12/09/11 7:52 PM This book is dedicated to my wife, Joanna, and to the “little one,” our beautiful darling daughter, Olivia. Love you both to bits! Xx ffirs.indd vii 12/09/11 7:52 PM ffirs.indd viii 12/09/11 7:52 PM ABOUT THE AUTHOR JERMAINE G. ANDERSON works within the Software Engineering department of British Sky Broadcasting in London, UK, currently as Scrum Master, where he manages the technical delivery for an Agile team responsible for the short-form online video platform. In recent years, Jermaine’s work has predominantly centered on video streaming, where he has been instrumental in creating cutting-edge and innovative products, specializing in Flash, the Flex framework, and, more recently, AIR. Jermaine grew up in the town of Wincobank, Sheffi eld, where he developed his passion for science, technology, art, design, and computing. From an early age he started coding on the family computer, using BASIC on an Amstrad CPC 6128. When Jermaine was eight years old, his father set him the task of designing a level for the critically acclaimed U.S. Gold computer game Gauntlet, which he completed, only to discover that there was a submission date for the level entry, and that date had passed, to Jermaine’s disappointment. He cites this as one of the early lessons he learned, to always do something for the enjoyment, and rewards come in various guises. Ultimately, problem solving and working with technology are his main drivers working in online media, driven by the Internet. Having earned a BSc (Hons) degree in Chemistry at The University of Birmingham, and a MSc in Computer Studies from Sheffi eld Hallam University, Jermaine devoted much of his professional career to working with Flash and online media over the last 11 years, taking a keen interest in mobile application development from early 2004. In 2005, Jermaine was awarded the “Best Productivity” category for his Mobile TV application, a concept that he designed and developed for the Macromedia Flash Lite Contest. Jermaine’s fi rst book, Professional Flash Lite Mobile Application Development (Wrox, 2010), focuses on structuring several mobile application concepts using the PureMVC framework targeting the Flash Lite player. His second book, Beginning Flash, Flex, and AIR Development for Mobile Devices, focuses on the Flex framework for mobile development, targeting Android, BlackBerry, and iOS devices. Jermaine tweets at www.twitter.com/jganderson and writes his personal blog at www.jgorganic.co.uk/blog. ffirs.indd ix 12/09/11 7:52 PM ffirs.indd x 12/09/11 7:52 PM ABOUT THE TECHNICAL EDITOR DARREN OSADCHUK has been creating games and applications in Flash for approximately 10 years. In 2005, he started Ludicrous Software and began developing games for Flash Lite-enabled mobile devices. Since then, Ludicrous Software’s games have been available on a variety of platforms, including Apple’s App Store, the Android Market, Amazon’s Appstore, BlackBerry App World, and Nokia’s Ovi Store. In addition to games published under the banner of Ludicrous Software, Darren has developed mobile and web games and applications for clients around the world. He has a Bachelor of Arts in Political Science from the University of Manitoba and a Master of Arts in Contemporary Social and Political Thought from the University of Victoria, British Columbia. ffirs.indd xi 12/09/11 7:52 PM ffirs.indd xii 12/09/11 7:52 PM CREDITS EXECUTIVE EDITOR PRODUCTION MANAGER Robert Elliott Tim Tate PROJECT EDITORS VICE PRESIDENT AND EXECUTIVE GROUP William Bridges PUBLISHER John Sleeva Richard Swadley TECHNICAL EDITOR Darren Osadchuk VICE PRESIDENT AND EXECUTIVE PUBLISHER Neil Edde PRODUCTION EDITOR Rebecca Anderson ASSOCIATE PUBLISHER Jim Minatel COPY EDITOR Kim Cofer PROJECT COORDINATOR, COVER Katie Crocker EDITORIAL MANAGER Mary Beth Wakefi eld PROOFREADER FREELANCER EDITORIAL MANAGER Nancy Carrasco Rosemarie Graham INDEXER ASSOCIATE DIRECTOR OF MARKETING Robert Swanson David Mayhew MARKETING MANAGER COVER DESIGNER Ashley Zurcher LeAndra Young BUSINESS MANAGER COVER IMAGE Amy Knies © Lise Gagne ffirs.indd xiii 12/09/11 7:52 PM ffirs.indd xiv 12/09/11 7:52 PM ACKNOWLEDGMENTS FIRST, I WANT TO THANK JOANNA for being an incredibly supportive wife, whom I have known for 12 years, and is still the most intelligent person I know. Jo is a real-life “fi refi ghter” and has helped me to accomplish this book, every step of the way. Thank you for your patience and understanding as I worked to fi nish the book at all kinds of crazy hours. And thank you for taking care of all the things that would have been a distraction to me. And no, I don’t mean LO. I love you. Olivia, mummy and daddy love you lots. You have been a true inspiration over the 18 months since you came into our world. Thank you for being an angel. I want to thank everyone at Wrox and Wiley for all their support. Thank you for sticking with the changes, especially when the volume of updates brought in for iOS seemed mega! Thank you to the former Wiley acquisition editor Scott Meyers, for bringing the book to the attention of executive editor Robert Elliot.