- Shopping Bag ( 0 items )
Professional Flash Mobile Development: Creating Android and iPhone Applications
Everything Flash developers need to know to create native Android and iPhone apps
This Wrox guide shows Flash developers how to create native applications for Android and iPhone mobile devices using Flash. Packed with practical examples, it shows how to build a variety of apps and integrate them ...
Professional Flash Mobile Development: Creating Android and iPhone Applications
Everything Flash developers need to know to create native Android and iPhone apps
This Wrox guide shows Flash developers how to create native applications for Android and iPhone mobile devices using Flash. Packed with practical examples, it shows how to build a variety of apps and integrate them with core mobile services such as Accelerometer, GPS, Photo Library,and more.
Professional Flash Mobile Development: Creating Android and iPhone Applications answers the demand for Flash-capable Android and iPhone apps.
WHAT'S IN THIS CHAPTER?
* Discovering Adobe AIR for Android
* What you can do on Android devices
* What you cannot do on Android
* A look at the Application Security Model
Not long after my wife and I got married, we moved 500 miles away to a new city. We were still the same couple as before, but we had to get used to our new environment — living in a new apartment, working in a new metro area, and finding new friends.
Developing Flash/ActionScript (AS3) apps for Android and iOS devices is quite similar. You already know the tool and the language that you've worked with for web and desktop-based Adobe Integrated Runtime (AIR) environments. Yet, you find yourself in a completely different runtime environment, with different capabilities and constraints that you never have to consider when working with desktop computers.
This chapter introduces these new two mobile environments and highlights some of the things you need to consider as you get started developing Flash-based applications for Android and iOS devices.
EXPANDING TO THE MOBILE WORLD
Fast forward several years. Although Flash is still utilized predominately for browser-based purposes, the overall Flash landscape is becoming more diversified. Flash isn't just for interactive media and light apps; you can use it to deploy full-fledged mission-critical applications. In addition to Flash, its ActionScript "brother" Flex offers a more traditional application development environment that utilizes both AS3 and Flash run time.
Flash is no longer constrained to a browser window. With the release of AIR in 2007, Flash and Flex developers could, for the first time, create standalone, cross-platform, rich Internet applications (RIAs) for Windows, Mac OS X, and Linux platforms. These AIR desktop applications not only had the look and feel of native apps but could take advantage of native operating system capabilities, such as local file access, native menus and UI elements, and OS-specific events.
Although Flash's dominance on the desktop is unquestioned, its entry into the rapidly emerging mobile phone world has been far more problematic. Apple's refusal to support the Flash plug-in in the iPhone in its Mobile Safari browser left Flash Web developers out in the cold. In response, Adobe engineers came up with a different plan to get Flash-created content and applications onto iOS devices (iPhone, iPad, iPod touch): bypass the browser and go native. In other words, Adobe engineers figured out a way to package Flash apps as native iPhone apps — yes, the same apps that you can download and install from the App Store (see Figure 1-1). Adobe made Packager for iPhone available in Flash Professional CS5.
Beyond the iOS universe, Adobe also is expanding support for Flash onto other mobile platforms, particularly Android and BlackBerry. But, unlike the roadblocks that Adobe encountered with Apple, Adobe has been providing support for both Flash Player and AIR on these other mobile devices (as shown in Table 1-1). However, a strategic goal for Adobe has been to ensure that you will be able to take the same Flash project that you use for deploying on the iPhone and outputting it as an AIR app on Android or BlackBerry.
DISCOVERING ADOBE AIR
Before you begin to tackle Flash-based mobile development, it's important to have some basic understanding of the runtime environment on which you will be developing applications.
Building for Android
Before you begin to develop Flash-based mobile apps, I wanted to "peek under the hood" for a moment and explain to you just exactly how Adobe can take a Flash file (.fla) and publish it as an .apk for Android or .ipa for iOS.
For Android apps, the process is not much different than AIR apps for the desktop. The AIR for Android run time provides an environment on which developers can build applications using Flash technologies and deliver it as a standalone application, outside of any browser. Users need to install the AIR for Android run time on their Android devices, and then Flash-based Android apps run on top of it.
AIR for Android embeds the cross-platform virtual machine Flash Player used to run media and apps created using Adobe Flash or Flash Builder. Inside of an AIR app, you have programmatic access to existing Flash Player API calls as well as some enhanced functionality for vector-based drawing, multimedia support, and a full networking stack.
AIR for Android also embeds SQLite, a database engine for enabling local database access. It is an extremely lightweight, open source, cross-platform SQL database engine that is embedded in many desktop and mobile products. Unlike most SQL databases, it does not require a separate server process and uses a standard file to store an entire database (tables, indexes, and so on). For more information on SQLite, go to www.sqlite.org.
When you publish a Flash file for Android, your .fla, .as source code, and other source files are transformed by the ActionScript compiler into a binary format called ActionScript Byte Code (ABC). The ABC is packaged inside a .swf file (see Figure 1-2). The .swf and supporting resource files are then packaged together as an Android package (.apk) ready for installation onto a device.
At run time, the .swf file inside of the Android app is processed by the ActionScript Virtual Machine (AVM2), which is part of the AIR for Android run time. The AVM2 loads the ABC file into memory and decodes it. The bytecodes are then run through an interpreter and executed as native machine code (see Figure 1-3) by the AIR run time. This process of bytecode compilation by the AVM2 is specific to the Android platform.
Building for iOS
So, while Android apps run on top of an AIR runtime environment that is installed separately, iOS apps wrap the runtime code inside of the app itself, making it self-contained. Not surprisingly, then, the process in which an iOS app is created, is quite distinct. Let me explain.
When you compile a Flash project for iPhone, the ABC code is compiled by the Low Level Machine Compiler (LLVM), which is an open source compiler infrastructure that is used to generate machine code for iOS. (Apple itself uses the LLVM). However, as shown in Figure 1-4, in its Packager for iPhone, Adobe provides an ActionScript front-end to the LLVM for handling Flash files.
While the AVM2 supports JIT for Web and AIR, LLVM uses Ahead-Of-Time (AOT) compilation to produce native ARM assembly code wrapped inside of an iPhone executable file. The .ipa also contains a .swf containing assets and a configuration file.
During the publishing process, the AIR Developer Tool (ADT) is used to add the .p12 certificate to the .ipa application file for developer authentication. The resulting .ipa is a native iPhone application ready for installation on your iPhone device.
WHAT YOU CAN AND CANNOT DO
Flash CS5 and Flash Builder allow you to create native Android and iOS apps, but it is important to understand from the get-go the capabilities and limitations of the types of functionality you develop.
Support for Android and iOS APIs are similar, but at the time of writing, not identical. Table 1-2 summarizes the API capabilities of Flash apps running on Android and iOS.
As you can see, some core mobile services are unsupported:
* Native UI controls
* Music player and library
The areas of strongest support center on multitouch and gesture events, Accelerometer, and persistent file and database storage. Both AIR for Android and Packager for iPhone are weaker than their native SDK counterparts in being able to integrate with other parts of the respective devices — both hardware and system services. Therefore, as you architect your apps, factor in those constraints.
Unsupported AS3 API Objects
When creating mobile applications, you have access to many parts of the core AS3 library and AIR API extensions. However, not all core and AIR functionality is supported on Android and iOS. The following is a list of AS3 API objects or members that are not supported:
* Accessibility * DNSResolver
* NativeApplication exit(), isSetAsDefaultApplication(), menu, and startAtLogin
* NativeWindow and NativeWindow.notifyUser()
* PDF support
* Socket support (DatagramSocket, SecureSocket, ServerSocket)
What's more, although you can use Flash Builder to create AIR for Android apps, the Flex MXML framework is not officially supported on Android and incompatible with iOS.
UNDERSTANDING THE AIR FOR ANDROID SECURITY MODEL
AIR for Android carries over the same basic security model that Adobe created for the desktop version of AIR. In the traditional desktop environment, desktop apps get permission in terms of what they can do and cannot do from the OS and the available permissions of the currently logged in user. They receive this level of access because the users need to explicitly install the app — effectively telling their computer that they trust the app they are about to launch. As a result, native apps have access to read and write to the local file system and perform other typical desktop functions.
Web apps, however, are far more restrictive because of the potentially malicious nature of scripting. As a result, web apps limit all local file access, can only perform web-based actions inside the context of a browser, and restrict data access to a single domain.
The hybrid nature of an AIR for Android application puts it somewhere between the traditional desktop and restrictive web security models. On the one hand, you can create an Android application that runs on top of the normal Android OS security layer. Therefore, it is able to read and write from the local file system. However, because AIR utilizes web technologies that, if unchecked, could be hijacked by a malicious third party and used in harmful ways when accessing the local system, AIR has a security model to guard against that happening. Specifically, AIR for Android grants permissions to each source or data file in an AIR application based on their origin and places them into one of two kinds of sandboxes.
The application sandbox contains all content that is installed with the app inside of the home directory of an application. Only these resources have access to the AIR for Android API and its runtime environment.
Adobe AIR does allow you to link in other local and remote content not inside the root directory of the application, but it places this content in a non-application sandbox. Content inside the nonapplication sandbox is essentially handled from a security standpoint just like a traditional web app and is not granted access to the AIR APIs (see Figure 1-5).
GETTING TO KNOW THE ANDROID SDK
Apart from using Flash CS5, Flash Builder, or the AIR command-line utilities, the only way to create Android applications is by working with the Android Software Developer Kit (SDK). The SDK is a set of APIs and development tools that developers use to create native Android apps. Although much of the Android SDK is not directly useful to Flash developers, you will still utilize some of its tools during your app development process. Therefore, you'll want to begin by downloading and installing the latest version at http://developer.android.com before continuing.
GETTING TO KNOW THE IOS SDK
Apart from Flash CS5, the only way to create iOS applications is by working with Apple's iOS Software Developer Kit (SDK). The SDK is a set of APIs and development tools that are used by Objective-C developers to create native iOS apps. While much of the iOS SDK is not useful to Flash developers, you can still utilize some of its profiling and diagnostic tools to debug your apps. Additionally, it is also a good idea to know what's in the SDK, particularly as you read Apple reference materials pertaining to iOS app development.
The core API frameworks include:
* Cocoa Touch framework is the core API used for developing iPhone apps. It includes support for multi-touch and gestures, accelerometer, and camera. * The Media API provides support for video, audio, and core animation processes. * Core Services are lower level services that provide networking, database, and thread support. * OS X Kernel is the lowest level of services providing basic File I/O, TCP/IP, security, and power management.
iOS SDK apps are built using Xcode developer tools. Xcode consists of the following:
* Xcode IDE is the Objective-C based development environment. * Interface Builder is used to create user interfaces in a visual environment and then link them into the Xcode project. * Instruments is a diagnostic tool that collects disk, memory, and CPU data of an app in real time. * Shark is a companion tool for profiling your app.
As Chapter 13 explains, you can use Shark and Instruments with your Flash-built apps.
In this chapter, you were introduced to Android and iOS application development using Flash CS5 and Flash Builder. You reviewed the API support for both mobile operating systems and explored what you can and cannot do in your Flash app. After that, you read aspects of the general AIR API that are available to you as you develop for Android devices. Finally, you took a quick survey of the Android SDK and iOS SDK. Although you do not need to use many parts of it for Flash apps, it is helpful to know that it contains support tools that can make your life easier.
Excerpted from Professional Flash Mobile Development by Richard Wagner Copyright © 2011 by John Wiley & Sons, Ltd. Excerpted by permission of John Wiley & Sons. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.
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
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
Creating a Provisioning Profile 32
Installing the Provisioning Profile 35
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 iPhone 71
CHAPTER 4: RETHINKING ACTIONSCRIPT PROGRAMMING 77
Conserving Memory and CPU Resources 77
ActionScript Practices 78
Reuse Objects 78
General Tips for Working with AS3 79
Event Handling 81
UI Practices 81
Graphics Practices 82
Miscellaneous Tips 83
General Application Practices 83
Frame Rate 83
GPU Rendering 84
Garbage Collection 84
Kitchen Sink Tips 85
CHAPTER 5: MULTITOUCH API 87
Understanding the Multitouch Jargon 87
Mouse Emulation Events 87
Touch Events 88
Gesture Events 88
Listening for Touch Events 89
Event Bubbling 89
Working with Touch Events 89
Coding the Document Class 90
Running the App 92
Working with the Swipe Gesture 96
Setting Up the Timeline 96
Adding a Sound Asset 96
Coding the Document Class 97
Running the App 101
Working with Rotate and Zoom Gestures 101
Coding the Document Class 102
Running the App 106
CHAPTER 6: DETECTING MOTION WITH ACCELEROMETER 109
Introducing Accelerometer and AccelerometerEvent 110
Listening for Accelerometer Events 111
Coding the Document Class 111
Running the App 114
Responding to Accelerometer Events 114
Creating the Sphere Class 115
Coding the Document Class 116
Running the App 121
Detecting Shaking 122
Coding the Document Class 122
Running the App 127
CHAPTER 7: IMPLEMENTING AUTO ORIENTATION 129
Enabling Your App to Rotate 129
Two Essentials for UI Reorientation 131
Detecting an Orientation Change 132
Changing Positioning Based on Orientation Changes 138
CHAPTER 8: GEOLOCATION API 145
Getting Geolocation Data 145
Enabling GPS Support for Android 147
Creating a Basic Geolocation Application 148
Coding the Document Class 148
Testing and Running the App 152
Creating a Compass App 153
Coding the Document Class 153
Running the App 159
Creating a Speedometer and Altimeter 160
Embedding a Font in Your App 160
Coding the Document Class 161
Configuring Landscape Orientation 167
Running the App 169
Sending Geolocation to a Web Service 169
Coding the Document Class 170
Running the App 178
CHAPTER 9: SERVICE INTEGRATION USING URL PROTOCOLS 179
Abstracting URL Protocols 180
Making Phone Calls from Your Application 181
Creating PhoneDialer.as 181
Using PhoneDialer in an App 182
Sending SMS Messages 187
Creating SMS.as 188
Adding SMS Support to PhoneServices App 189
Running the App 189
Sending E-mails 191
Creating Mail.as 191
Sending Mail from an App 194
Android: Adding Permissions 196
Running the App 197
Pointing on Google Maps 198
Creating GoogleMaps.as 199
Using GoogleMaps in an App 200
Android: Setting Permissions 206
Running the App 206
CHAPTER 10: ANDROID CAMERA, CAMERA ROLL, AND MICROPHONE 209
CameraUI: Launch and Return 210
Camera: Creating a Live Video Feed 216
Tapping into the Camera Roll 221
Capturing Sounds with the Microphone 228
CHAPTER 11: FILE MANAGEMENT 237
Understanding the Android File and Directory Structure 237
Working with Directories, Files, and File Streams 238
Working with Directories 238
File System Operations 241
Reading and Writing Files 244
Reading a File 245
Writing to a File 246
Android Case Study: Jots 246
Coding the Document Class 248
Running Jots 253
CHAPTER 12: LOCAL DATABASES 255
Working with a SQLite Database 255
Open a Database Connection 256
Creating a Synchronous Connection 256
Creating an Asynchronous Connection 256
Creating Tables 257
Making a SQL Query 262
Inserting and Updating Records 263
PART IV: TESTING AND DEBUGGING
CHAPTER 13: REMOTE DEBUGGING 273
Establishing a WIFI Connection 273
Using the AIR Debug Launcher 274
Android Debugging 274
Remote Debugging inside the Flash IDE 274
Remote Debugging from the Command Line 276
Debugging with Android SDK’s Logcat 277
iOS Debugging 277
Remote Debugging inside the Flash IDE 277
Viewing GPU Rendering Diagnostics 278
CHAPTER 14: SUBMITTING YOUR APP TO THE APP STORE 279
Preparing Your Android App 279
Getting a Screenshot 280
Submitting Your App to the Android Market 281
Registering Your Developer Profile 281
Submitting Your App 282
Preparing Your iOS App 285
Getting a Distribution Certificate 285
Creating a Distribution Provisioning Profile 287
Publishing a Distribution Release of Your App 288
Submitting Your App to the Apple App Store 288
APPENDIX A: APPLICATION DESCRIPTOR SETTINGS 291
APPENDIX B: COMPILING APPLICATIONS
FROM THE COMMAND LINE 305
Posted April 26, 2011
This is my second book that I bought to enter into the world of Android Application Development and it made setting up the environment easy as compared to online tutorials and the other book i purchased. There were a few things that were a little unclear BUT... if you have a little sense and keep google handy, you should be ok. BE PATIENT! (i did take my time and went slowly setting it up in 3 days!) so if you are a beginner do not expect that this will be CAKE! I havent gotten through the entire book and with my very basic knowledge of flash i made a simple app in one day and posted the app on the android market. There are a few more things that i would like to know but this book has been good so far. and this book WILL NOT solve all of your app problems and questions. use multiple resources!!!Was this review helpful? Yes NoThank you for your feedback. Report this reviewThank you, this review has been flagged.