Flash Mobile This page intentionally left blank Flash Mobile Developing AnDroiD AnD ioS ApplicAtionS Matthew DaviD A MSTERDAM • BOSTON • HEIDELBERG • LONDON • NEW YORK • OXFORD PARIS • SAN DIEGO • SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO Focal Press is an imprint of Elsevier Focal Press is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA The Boulevard, Langford Lane, Kidlington, Oxford, OX5 1GB, UK © 2011 Elsevier Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publisher's permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions. This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein). Notices Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods, professional practices, or medical treatment may become necessary. Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information, methods, compounds, or experiments described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility. To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein. ISBN: 978-0-240-81568-8 For information on all Focal Press publications visit our website at www.elsevierdirect.com 11 12 13 14 15 5 4 3 2 1 Printed in the United States of America Dedication Life is comprised of moments. It is what is said and done in these “moments” that defines our lives. My family is forever blessed that the following people shared moments from their lives with us: Dick and Anne: You both ran the gauntlet with us and we all made it through! We treasure your friendship in ways that words will never be enough. Marcia, my “mom-in-law”: You are always there, and you are always supporting us. We love you deeply. Arthur: At the hardest time, you were there. I will never forget. My deepest thanks I give to my wife and children. I love you, hon. v This page intentionally left blank ContentS Author’s Note ................................................................................................xi Foreword .....................................................................................................xiii Section 1 Setting up Flash CS5 for Android Development .................................................3 Designing and Developing for Android Hardware ......................................7 Configuring the Android SDK Publish Setting ..........................................12 Setting up Flash CS5 for Android Development .......................................15 Installing Your AIR Application onto an Android OS .................................17 Building Your First Application for Android Using Flash CS5 ..................18 Project 1: Creating Your First App Using Flash CS5 .......................................27 Setting up Your Development Environment ..............................................27 Creating the Graphics ..................................................................................35 Building an Application ...............................................................................37 Running Your App on Your Android Phone ................................................43 Section 2 Rapid Android Development in Flash CS5 ........................................................49 Creating Content for Your Android Phone That Does Not Require Programming ..........................................................................49 Animation Techniques You Should Use on Mobile Devices .....................50 Controlling Sound .......................................................................................71 Controlling Video .........................................................................................80 Working in the Third Dimension .................................................................83 What You Have Learned ..............................................................................86 vii viii Contents Project 2: optimizing Animation, Audio, Video, and Component Use in Your AIR for Android Apps.......................................................................89 Your Building Blocks ....................................................................................89 Importing Files into Flash ...........................................................................91 Adding Animation ........................................................................................94 Adding Audio ...............................................................................................96 Adding Video ................................................................................................96 Testing on Your Android Phone ..................................................................96 Section 3 Developing Mobile Apps using ActionScript ................................................101 Enabling Flash to Execute Solutions Faster with AVM 2.0 .....................102 What You Can Expect When You Use AS3 ...............................................102 Controlling Data ..........................................................................................113 Controlling Text ...........................................................................................116 Drawing with the Shape Class ...................................................................117 Using ActionScript to Control Animation, Audio, and Video in Your Android Apps .......................................................................118 Extending Flash with Open Source Libraries ..........................................125 Summary ....................................................................................................125 Project 3: Building Sprite’s 123 ........................................................................127 Setting Up the Project to Run on an iPhone ............................................128 Setting Up the Timeline.............................................................................131 Adding Interaction to Your Number Screens ..........................................134 Completing the Application ......................................................................137 Section 4 Leveraging Custom iPhone and Android Interface Calls with ActionScript ......................................................................................141 Using Gestures in Your Apps ....................................................................142 Working with Gestures ..............................................................................146 Contents ix Which Way Is Up? Controlling Orientation with the Android Accelerometer .......................................................................150 Knowing Where You Are, Using Geolocation ..........................................152 Loading RSS Data into Flash ....................................................................153 Adding Permissions to Your Apps ............................................................156 Loading Web Pages into the StageWebView ...........................................157 Controlling the Use of the Microphone ...................................................159 Controlling the Camera .............................................................................161 Additional Features on AIR 2.5 for Android .............................................164 Summary ....................................................................................................164 Project 4: Building a Gesture-Driven Application .......................................165 Getting Started ...........................................................................................165 Navigating Using the Tap Gesture ............................................................167 Adding a Swipe Gesture to Move from One Screen to the Next ...........172 Adding Drag and Drop Gestures ..............................................................174 Using Geolocation to Find Where You Are ..............................................176 Summary ....................................................................................................178 Section 5 Building Games with Flash for the Mobile Market ......................................181 Getting Started with Game Development ...............................................181 Making It Easier to Write Code with Libraries .........................................184 Using Game Engines .................................................................................203 Developing Your Game ..............................................................................240 Project 5: Building a Mobile Game .................................................................241 Playing Space Rocket ................................................................................242 Getting Started ...........................................................................................242 Game Assets and Default Layer Structure ...............................................244 Adding the Code to the Game ..................................................................245 Controlling the Missiles ............................................................................251 Controlling the Falling Rocks ....................................................................254
Description: