ebook img

Foundation Flash Applications for Mobile Devices PDF

510 Pages·2007·9.085 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Foundation Flash Applications for Mobile Devices

Foundation Flash Applications for Mobile Devices Richard Leggett Weyert de Boer Scott Janousek Foundation Flash Applications for Mobile Devices Copyright © 2006 by Richard Leggett, Weyert de Boer, Scott Janousek All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13: 978-1-59059-558-9 ISBN-10: 1-59059-558-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc. Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is freely available to readers at www.friendsofed.comin the Downloads section. Credits Lead Editor Production Editor Chris Mills Laura Esterman Technical Reviewers Compositor Marco Casario Diana Van Winkle Cesar Tardaguila Artist Editorial Board April Milne Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Proofreaders Jonathan Gennick, Jonathan Hassell, Liz Welch James Huddleston, Chris Mills, Lori Bring Matthew Moodie, Dominic Shakeshaft, Indexer Jim Sumser, Matt Wade Toma Mulligan Project Manager | Production Director Cover Image Designer Grace Wong Corné van Dooren Copy Edit Manager Interior and Cover Designer Nicole Flores Kurt Krames Copy Editors Manufacturing Director Heather Lang Tom Debolski Damon Larson Assistant Production Director Kari Brooks-Copony CONTENTS AT A GLANCE About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv About the Main Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii About the Cover Image Designer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi PART ONE GETTING STARTED 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1 Macromedia and Adobe Flash: An Overview . . . . . . . . . . . 3 Chapter 2 Mobile Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Chapter 3 Flash Lite 1.1 and Your First Flash Lite Application . . . . 43 Chapter 4 Flash Lite 2.X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 PART TWO LET’S GET DEVELOPING! 131 . . . . . . . . . . . . . . . . . . . . Chapter 5 Application Development . . . . . . . . . . . . . . . . . . . . . . . . 133 Chapter 6 Mobile Gaming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Chapter 7 Flash Lite Mobile Entertainment Basics . . . . . . . . . . . . . 225 Chapter 8 Flash Mobile Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Chapter 9 Flash Mobile Video. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Chapter 10 Extending Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 PART THREE THE POST-DEVELOPMENT STAGE 389 . . . . . . . . . . Chapter 11 Distribution and Deployment . . . . . . . . . . . . . . . . . . . . 391 Chapter 12 The Future of Flash in the Mobile World . . . . . . . . . . . 427 PART FOUR APPENDIXES 439 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Appendix A Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 Appendix B FSCommand2 Commands . . . . . . . . . . . . . . . . . . . . . . . 445 Appendix C Glossary of Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 iii CONTENTS About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv About the Main Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii About the Cover Image Designer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi PART ONE GETTING STARTED 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1 Macromedia and Adobe Flash: An Overview . . . . . . . . . . . 3 A brief history of Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Object-oriented programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 ActionScript 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Rich Internet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Peripheral Flash technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Flash Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Flash Media Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Stand-alone SWF wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Flex and the Flash platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Alternatives to Flex and the Flash IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Open source Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Mobile Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Flash for Pocket PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 FlashCast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Chapter 2 Mobile Devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 The wireless revolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Mobile evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Content and infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 What is 3G? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Cultural acceptance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Synchronization and convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 v CONTENTS Invasive nature of personal devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 A CRM dream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Types of devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Mobile phones and their operating systems . . . . . . . . . . . . . . . . . . . . . . . . . . 23 PDAs and their operating systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Other devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Device limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 CPU and RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Screen size and resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Screen color depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Keypads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Other input devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Ergonomics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Connectivity and network speeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Data storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Other limitations to consider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 User expectations and human-computer interaction (HCI) limitations . . . . . . . . . . . 31 Self-inflicted limitations (by you, the developer) . . . . . . . . . . . . . . . . . . . . . . . 32 Other existing technologies for mobile development . . . . . . . . . . . . . . . . . . . . . . 32 Java 2 Mobile Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Symbian native C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Binary Runtime Environment for Wireless (BREW) . . . . . . . . . . . . . . . . . . . . . . 35 Python for Symbian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 What makes a device successful? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 The Pogo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 The Nokia 3210 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Successful applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Business and productivity applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Market opportunities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 The future of devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Chapter 3 Flash Lite 1.1 and Your First Flash Lite Application. . . . . 43 Setting up your Flash Lite studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Flash MX 2004 Professional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 The Flash Lite player for the Flash IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 The Flash Lite 1.1 publish profile configuration file . . . . . . . . . . . . . . . . . . . . . 45 The device’s configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Device templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Obtaining the Flash Lite player for your device . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Creating a simple test application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 A Flash Lite 1.1 ActionScript primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Undefined variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 vi CONTENTS Slash notation (targeting movie clips) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Relative paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Variable scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Control structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Emulating arrays with eval() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Creating custom functions with call() Coding conventions . . . . . . . . . . . . . . . . . . . . 66 Whitespace and new lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Variable naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Text field variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Keywords and reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Statement terminators (semicolons) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Dot syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 FSCommand2 commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Using FSCommand2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Getting the date and time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Useful functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 String functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Custom string functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Number functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Time line functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Movie clip functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 General functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 mitations of ActionScript for Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 getURL() and loadVariables() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 GET character limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Local storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Maximum integer value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Version inconsistencies and common pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Variable initialization and undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Checking for a movie clip’s existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Renaming movie clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 add vs. + (string concatenation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 SWF tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 The Adobe Flash Lite 1.1 CDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Flash Lite 1.1 Authoring Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Interface elements (components) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Chapter 4 Flash Lite 2.X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Flash Lite 2.X ActionScript primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Variables and strict data typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Variable scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Programming constructs new to Flash Lite 2.0 . . . . . . . . . . . . . . . . . . . . . . . . 105 vii CONTENTS New objects in Flash Lite 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Key and ExtendKey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 TextField and TextFormat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 MovieClipLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 LoadVars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 XML and XMLNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Structuring a Flash Lite 2.0 application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 The time-line–based method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 The pure code method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 The EventDispatcher class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Dynamic MovieClips and buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 createEmptyMovieClip() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 attachMovie() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 getNextHighestDepth() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 onEnterFrame() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 MovieClip buttons and the Delegate class . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Unsupported code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Mobile shared objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 MSO example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 More on mobile shared objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 The System.capabilities object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Device functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Extending the drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Improvements and changes in Flash Lite 2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 XMLSocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 In-line text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 TextField variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Escape/Unescape changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 File locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 PART TWO LET’S GET DEVELOPING! 131 . . . . . . . . . . . . . . . . . . . . Chapter 5 Application Development . . . . . . . . . . . . . . . . . . . . . . . . 133 User interface design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Navigation and interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Aesthetics vs. functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Key events and key catcher buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Custom tab order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Common UI guidelines and feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Fail safes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 viii CONTENTS The Flash Lite 1.1 CDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 The example files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 The components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Improving the CDK components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 The Flash Lite 2.0 CDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 The documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 The example files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 The tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Consuming data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 loadVariables() (Flash Lite 1.0+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 LoadVars (Flash Lite 2.X) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 XML (Flash Lite 2.X) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Interaction with server-side scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Interaction with a database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Integrating with the phone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 getURL() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 FSCommand2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Example application: Stock quote client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 The server side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Stock quote client for Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 StockQuote Lite for Flash Lite 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Adapting StockQuote Lite for Flash for Pocket PC . . . . . . . . . . . . . . . . . . . . . 181 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Chapter 6 Mobile Gaming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Introduction to the mobile game scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 PDAs and phones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Handheld consoles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Game genres . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Code samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Making things move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Moving an item directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Moving several items at once . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Moving items around a point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 The physics of motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Velocity, direction, and momentum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Creating an ease out tween . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Player input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 One-button games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Using input with motion in a jump example . . . . . . . . . . . . . . . . . . . . . . . . . 194 Collision detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 MovieClip.hitTest() (Flash Lite 2.0+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 The registration point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Bounding box collisions (Flash Lite 1.1) . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Circle-to-circle(s) collisions (Flash Lite 1.1+) . . . . . . . . . . . . . . . . . . . . . . . . . 201 Line-to-circle collisions (Flash Lite 1.1+) . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 ix CONTENTS Collision reactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Why so slow? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Efficient math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Precalculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Using short variable names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Game assets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Vector graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Bitmap graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Sounds and music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Saving and loading high scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Sample games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Mad Bomber (Flash Lite 1.1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Snake (Flash Lite 2.0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 BlackJack (Flash Lite 2.1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Chapter 7 Flash Lite Mobile Entertainment Basics . . . . . . . . . . . . . 225 Evolution of Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Potential impact of Flash Lite 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Market trends in mobile entertainment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Asian-Pacific region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 North American region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 European region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 What are the global trends? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Flash Lite content types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 What content types are available? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Flash Lite 1.1 content types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 i-mode–specific content types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Flash Lite 1.1 content types vs. Flash Lite 2 content types . . . . . . . . . . . . . . . . . 234 Flash Lite 1.1 ActionScript review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 random() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 setProperty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 tellTarget() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Choosing your target device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Developing Flash Lite wallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Star field static wallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Animated snowfall wallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Flash Lite screen savers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Creating a Flash Lite screen saver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Matrix screen saver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Chaku Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Charajam: animated Flash Lite content . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 x CONTENTS Chapter 8 Flash Mobile Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Flash Lite sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Device sound vs. native sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Mobile sound formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Sound Bundler tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Flash Lite 1.1 sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Flash Lite 2 sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Creating a custom MP3 player with Flash Lite 2 . . . . . . . . . . . . . . . . . . . . . . . . . 285 The MP3 player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Synchronizing device sounds with animation . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 Syncing device sound with time line animation . . . . . . . . . . . . . . . . . . . . . . . 292 Media Playback API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Flash Lite sound considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 File size, memory, and CPU limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Sound quality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Using 3GP audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Chapter 9 Flash Mobile Video. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Fundamentals of Flash Mobile video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 Flash video on Pocket PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 Mobile video formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 Converting desktop video to mobile video . . . . . . . . . . . . . . . . . . . . . . . . . 304 Flash Lite video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Flash Lite 2 device video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Device video example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Media Playback API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 Thoughts on device video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Reaping the benefits of device video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Avoiding the limitations of device video . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 The future of mobile Flash video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 Chapter 10 Extending Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 Limitations of Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 The XMLSocket class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 Video playback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 Creating components for Flash Lite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 Differences among Flash Lite 1.X and 2.0 components . . . . . . . . . . . . . . . . . . . 341 Building an inline text field for Flash Lite 2.0 . . . . . . . . . . . . . . . . . . . . . . . . 342 Writing text files using Write2File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 What you need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Compiling Write2File under Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 Compiling Write2File under Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Creating an evaluation version for Flash Lite applications . . . . . . . . . . . . . . . . . 356 xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.