Beginning Flash, Flex, and AIR Development for Mobile Devices

Overview

Easily create cross-platform, standalone native applications for mobile devices using AIR

AIR allows you to develop the rich, creative, interactive media experiences for mobile applications. This easy-to-follow guide covers everything you need to know to create rich mobile applications using Adobe Flash Builder. Packed with examples, this book shows you how to build applications for mobile devices using a combination of ActionScript, the Flex framework and AIR. You'll discover ...

See more details below
Other sellers (Paperback)
  • All (13) from $1.99   
  • New (10) from $1.99   
  • Used (3) from $16.99   
Sending request ...

Overview

Easily create cross-platform, standalone native applications for mobile devices using AIR

AIR allows you to develop the rich, creative, interactive media experiences for mobile applications. This easy-to-follow guide covers everything you need to know to create rich mobile applications using Adobe Flash Builder. Packed with examples, this book shows you how to build applications for mobile devices using a combination of ActionScript, the Flex framework and AIR. You'll discover how these applications are able to run across multiple mobile and tablet devices, targeting Google Android, Apple iOS, and BlackBerry platforms. Plus, hands-on instructions detail how to leverage the unique hardware and software features that are available to each various device and platform.

  • Serves an ideal starting point for learning to create rich, interactive applications for mobile devices
  • Includes hands-on examples that demonstrate how to best use the variety of hardware and software features
  • Escorts you through mobile app concept to completion with sample code and step-by-step instructions
  • Discusses such topics as enabling multitouch; developing for multiple screen sizes; maintaining app data; and much more

Start building standalone mobile applications today with Beginning Flash, Flex, and AIR Development for Mobile Devices.

Read More Show Less

Product Details

  • ISBN-13: 9780470948156
  • Publisher: Wiley, John & Sons, Incorporated
  • Publication date: 10/25/2011
  • Edition number: 1
  • Pages: 400
  • Sales rank: 1,455,898
  • Product dimensions: 7.42 (w) x 9.10 (h) x 0.79 (d)

Meet the Author

Jermaine G. Anderson works within the Software Engineering department of BSkyB in London, where he manages an agile team responsible for short-form media and the online video platform.
Read More Show Less

Read an Excerpt

Beginning Flash, Flex, and AIR Development for Mobile Devices


By Jermaine G. Anderson

John Wiley & Sons

Copyright © 2011 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-0-470-94815-6


Chapter One

An Introduction to Flash, Flex, and AIR

WHAT YOU WILL LEARN IN THIS CHAPTER:

* An overview of the Adobe Flash platform

* Outlining the key concepts of the ActionScript 3.0 language

* Exploring the Flex framework and MXML components

* A brief introduction to Adobe AIR

In this chapter you'll take a look at each of the core elements of the book: Flash, Flex, and AIR.

First you'll cover a number of the core aspects of Flash and the programming language ActionScript 3.0, which this book uses.

You'll then explore the key features of the Flex framework and MXML components, looking at examples through code snippets.

Lastly, you'll be introduced to features of AIR, the Adobe Integrated Runtime.

ADOBE FLASH

Adobe's Flash platform consists of several Flash-based runtime clients: Flash Player, Flash Lite, and Adobe AIR. Each run time has its own set of functions and APIs that are specific for that run time.

The Flash platform also encompasses a component framework, Flex. All these elements, the runtime clients and component frameworks, support and utilize the SWF format.

Flash is predominantly used for the web deployment of rich content and applications. It is installed as a web browser plug-in, and can also run content in standalone mode. The Adobe Flash logo is shown in Figure 1-1.

Flash on Mobile Devices

There are currently two ways in which Flash has dedicated support on mobile devices. These involve using Flash Lite and Flash Player, respectively.

Flash Lite 4.0

Flash Lite runs Flash content and applications intended to run on performance-limited mobile devices. Flash Lite offers a different set of capabilities compared with Flash Player. Until recently Flash Lite supported only the ActionScript 2.0 (AS2). Currently Flash Lite is in version 4.0 and the run time now supports ActionScript 3.0 (AS3).

To learn more about Flash Lite and how you can create mobile applications using the technology, check out the book Professional Flash Lite Mobile Application Development, by Jermaine Anderson (Wrox, 2010).

Flash Player 10.x

Flash Player 10.1 was the first release of Flash Player aimed at supporting the development of content and SWF format deployment to both traditional web browser and mobile devices.

At the time of writing, a beta for Adobe Flash Player 11 was underway, allowing developers to preview new and enhanced features targeting the next release of the run time. With the potential for new APIs to be dropped, none of the features could be covered in this book, but look for an update. For more information, visit the Adobe Labs website (labs.adobe.com/technologies/) and search for Adobe Flash Player 11.

This book centers on the development of Flash content targeting the latest release, Adobe Flash Player 10.3 using AS3.

Flash is fully supported on Google Android and the BlackBerry Tablet OS mobile platforms. Unless you've been hiding under a rock for the past few years, you'll know Flash isn't supported on the Apple iOS platform. However, using AS3 and AIR, you can target your applications to run on the platform via standalone applications.

ACTIONSCRIPT 3.0

AS3 is an object-oriented language for creating media content for playback in the Flash runtime clients' Flash Player, Flash Lite, and Adobe AIR.

ECMAScript

The core of the AS3 language is based on the ECMAScript 4th Edition language specification, which you can view on the ECMA International website at www.ecmascript.org/. You can view the AS3 specification at http://livedocs.adobe.com/specs/actionscript/3.

AS3 has a syntax that is very similar to Java; it is also similar to the widely used JavaScript, the popular language used in web browsers. If you are from either of these programming disciplines, then AS3 will be very familiar.

ECMAScript 4 defines a number of rules for how code is written in AS3, including grammar and syntax. These dictate that code be written in a particular way, which should mean that code written by one developer will be recognizable to another.

A number of core programming concepts, such as variables, functions, classes, objects, expressions, and statements, form part of ECMAScript 4 and are inherited by AS3.

ECMAScript 4 also defines several built-in data types for AS3, allowing developers to utilize frequent data types such as an array, Boolean, number, and string.

Key Concepts

You need to grasp a number of important key concepts when programming with AS3; these will stand you in good stead for the rest of this book. Here you'll take a look at some of these concepts.

Classes, Objects, and Instances

A class is what gives an object its properties and the features by which an object accomplishes particular tasks through its methods and functions. A class is essentially a blueprint for an object.

AS3 classes are text-based files identified by the .as file extension. A class is defined by the class keyword, followed by the name of the class, which should start with a capital letter. It is this class name that must match the filename the class is created in. The following snippet shows you an example of a class called Mobile that's being defined:

class Mobile {}

An object represents part of a program that describes a particular thing. That thing could be a shape that has three sides and is colored blue; a film that has a PG rating; or a mobile device that allows you to store contacts. An object can be anything you can think of.

Objects have properties that give them their character and also have methods that allow them to carry out particular tasks.

In AS3, objects are created from classes by instantiating them, calling the new keyword before the class name and parentheses (). The following snippet shows you an example of the Mobile class being instantiated:

new Mobile();

Packages

A package defines the path to a class, which should be uniquely identified in respect to other classes that may have the same class name. Packages also reflect the folder structure.

Ultimately, packages are used to avoid conflicts between classes.

It is best practice to give packages meaningful names. Grouping similar classes together in a package is common practice and makes it easier to search and utilize different classes when programming.

The Mobile class could well be placed in a package called devices, sitting alongside another class called Tablet, if that class were to be created.

package devices { class Mobile {} }

While this example shows a fully qualified package, the naming convention is usually more granular, and with the package name defined for a class set as a dot-delimited, reverse-DNS-style string. For example, the devices package declaration could quite easily have been referenced as part of the Wrox.com domain, with the Chapter 1 name com.wrox.ch1.devices, as shown in the following snippet:

package com.wrox.ch1.devices { class Mobile {} }

Packages are also used when importing classes into AS documents, denoted by the import keyword, as shown in the following code snippet where the package com.wrox.ch1.devices example is used again:

import com.wrox.ch1.devices.Mobile;

A class has to be referenced by its full package reference before it can be used.

Functions, Methods, and Scope

A function is what allows an object to do a particular task and perform a set of reusable instructions. Functions are defined using the function keyword followed by the name of the task.

Class Scope Modifiers

Four keywords give scope to the properties and functions of an object: public, private, protected, and internal.

The public scope modifier means that a variable property or function can be accessed anywhere. The protected scope modifier means that only the current class and subclasses can use the variable or function. The private scope modifier restricts access to within the class only, and the internal scope modifier restricts the scope to the package it is contained in.

The Class Constructor

The constructor of a class is what initializes an object and creates it. The constructor is basically a class method, which must be declared public. The following snippet shows the constructor for the Mobile class, which is simply Mobile():

package devices { public class Mobile { public function Mobile() { // Code to initialize Mobile } } }

Return Types

Depending on the set of instructions found in the function, the return type gives an indication of the value that can be generated by the function call. In the following snippet, a public function called launchApp() is defined, with the return type specified as void:

package devices { public class Mobile { public function Mobile() { // Code to initialize Mobile } public function launchApp():void { // Code to launch an app on the mobile. } } }

The void keyword indicates that a value isn't expected to be returned by the function. Also note that class constructors don't specify a return type.

Variables

A variable is a unique identifier associated with an object that can hold a reference to a value. In AS3, data types are given to variables so that they can be checked at compile time. Variables are defined by the var keyword and then followed by the variable name.

In a class, variables that are added outside of functions can be referenced within the scope of the class; these are known as instance variables. These describe an object's characteristics and are what give an object its properties.

The following code snippet shows two private variables being declared: contacts, an Array data type, and phoneNumber, a Number data type:

package devices { public class Mobile { private var contacts:Array; private var phoneNumber:Number; public function Mobile() { // Code to initialize Mobile } public function launchApp():void { // Code to launch an app on the mobile. } } }

The following code demonstrates creating a Mobile object and assigning it to the variable mobileObj:

var mobileObj:Mobile = new Mobile();

Notice here that the data type assigned to the object is Mobile. Whenever you instantiate an object in this way, you need to define the data type on the variable; otherwise, you'll get a "variable has no type declaration" warning.

Within a method or function, instance variables can be used to set or reference data values. In the following code snippet the phoneNumber variable is assigned a value within the constructor method of Mobile, using the this keyword:

package devices { public class Mobile { private var contacts:Array; private var phoneNumber:Number; public function Mobile() { this.phoneNumber = 011003637; } public function launchApp():void { // Code to launch an app on the mobile. } } }

Static Variables and Methods

A static reference relates to class methods and variables that can be referenced without instantiating the class and creating an object.

In the following code snippet, the Mobile class is given the static variable deviceType which is defined as a string and is given the value Smartphone. A static function called switchOn() is also defined.

package devices { public class Mobile { public static var deviceType:String = "Smartphone";

private var contacts:Array; private var phoneNumber:Number;

public function Mobile() { this.phoneNumber = 011003637; }

public function launchApp():void { // Code to launch an app on the mobile. }

public static function switchOn():void { // Code to switch on the device. } } }

The following code demonstrates how you would call the switchOn() function:

Mobile.switchOn();

Parameters and Arguments

A parameter is a local variable that is defined and given a data type in the parentheses of a function declaration.

Instance methods allow you to define functions that exhibit an object's features and the things it can do. Parameters can be defined on instance methods to allow values to be passed to an object.

The following snippet shows a new instance method for the Mobile class defined, called addContact(). The method has a public scope and has two parameters: cName, a String data type representing a contact's name, and cNumber, a Number data type representing the contact's mobile number.

package devices { public class Mobile { public static var deviceType:String = "Smartphone";

private var contacts:Array; private var phoneNumber:Number;

public function Mobile() { this.phoneNumber = 011003637; }

public function addContact(cName:String, cNumber:Number):void { // Code to add a new contact }

public function launchApp():void { // Code to launch an app on the mobile. }

public static function switchOn():void { // Code to switch on the device. } } }

Note that local variables are only temporary.

To invoke or call the addContact() method, you need to use an instance of the Mobile class and supply what are called the arguments for the method. In this case there are two arguments, as shown in the following snippet:

var mobileObj:Mobile = new Mobile(); mobileObj.addContact("Olivia", 736300110);

Here the values Olivia and 736300110 are both arguments. Each argument needs to match the data types of the parameters specified for the method.

Conditional and Loop statements

A conditional statement is code that executes when a specific condition has been met.

In the following code snippet another static function called switchOff() has been added to the Mobile class. Here you will see a conditional if statement that checks the variable isOn, a Boolean value which is initially set to false in the class. In switchOn(), there is an if statement to check to see if the isOn value is false; this is indicated by the exclamation (!) preceding the Boolean value (that is, !isOn). The switchOff() function demonstrates another way of writing the same by asking whether the isOn variable is equal to false, and then executing the code within the else block of the if statement by setting isOn to false.

package devices { public class Mobile { public static var deviceType:String = "Smartphone";

private var contacts:Array; private var phoneNumber:Number; private var isOn:Boolean = false;

public function Mobile() { this.phoneNumber = 011003637; } public function addContact(cName:String, cNumber:Number):void { // Code to add a new contact }

public function launchApp():void { // Code to launch an app on the mobile. }

public static function switchOn():void { if(!isOn) { isOn = true; // Now add code to switch on the device. } else { // Do nothing, device is already on. } } public static function switchOff():void { if(isOn == false) { // Do nothing, device is already off. } else { isOn = false; // Now add code to switch off the device. } } }

}

A loop is a statement in which code is executed for as long as a particular condition is met.

The following code snippet shows how the switchOn() function could be updated to include a while loop statement, which executes the code within the block as long as the seconds variable is more than 0. The value held by seconds reduces by 1 each time the loop runs.

(Continues...)



Excerpted from Beginning Flash, Flex, and AIR Development for Mobile Devices by Jermaine G. Anderson 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.

Read More Show Less

Table of Contents

INTRODUCTION xxi

CHAPTER 1: AN INTRODUCTION TO FLASH, FLEX, AND AIR 1

Adobe Flash 1

Flash on Mobile Devices 2

ActionScript 3.0 2

ECMAScript 2

Key Concepts 3

The Flex Framework 11

Flex 4.5.1 11

MXML 12

Spark Library Components 14

Data Binding 21

Flex Mobile Application Structure 22

Considerations for Mobile Development 31

Adobe AIR 31

Summary 32

CHAPTER 2: GETTING STARTED 35

Using Flash Builder 4.5.1 35

Working with Workspaces 36

Using the Flash Perspective 37

Using the Flash Debug Perspective 38

Using the Source and Design Views 39

Creating a Mobile Project Using Flash Builder 41

Creating a Hello World App Example 41

Defi ning Run Confi gurations 51

Running Mobile Applications on the Desktop 52

Running Mobile Applications on the Device 55

Summary 64

CHAPTER 3: BUILDING AIR APPLICATIONS FOR ANDROID, BLACKBERRY, AND IOS DEVICES 67

AIR Application Descriptor Files 67

Setting Properties in the AIR Application Descriptor File 68

Manually Editing the Application Descriptor File for the Hello World App 69

BlackBerry Tablet OS Confi guration 79

Packaging for Google Android 82

Packaging for Apple iOS 88

Packaging for BlackBerry Tablet OS 94

Updating AIR Applications 96

Retrieving Details from the Application Descriptor File 97

Using the Version Number 97

Summary 98

CHAPTER 4: TOUCH, MULTITOUCH, AND GESTURES 101

Multitouch Interactions 102

Determining Touch Input Support 102

Creating a Multitouch and Gestures App Example 103

Touch Event Handling 106

Registering Touch Events on Interactive Objects 114

Determining the Supported Touch Points 117

Gesture Interactions 117

Determining Which Gestures Are Supported on a Device 117

Gesture Events and Event Handling 118

Registering Gesture Events on Interactive Objects 119

Handling Gesture Events 124

Utilizing the Multitouch Panel in Device Central 128

Summary 128

CHAPTER 5: DEVELOPING FOR MULTIPLE SCREEN SIZES 131

Considerations for Multiple Screen Sizes 132

Pixel Density 132

Utilizing Device DPI 133

Adapting Content to Stage Size 138

Using the StageScaleMode and StageAlign Classes 138

Handling Stage Resize Events 140

Creating the Sprite Layout App Example 140

Handling Device Orientation 151

Using the StageOrientation Class 152

Using the StageOrientationEvent Class 152

Using Layouts in Flex 154

Aligning Items in Group Containers 155

Summary 174

CHAPTER 6: DEBUGGING APPLICATIONS 177

Setting Breakpoints 177

Global Error Handling 188

Handling Uncaught Errors 188

Try…Catch Statements 191

Stepping through Code 193

Summary 196

CHAPTER 7: WORKING WITH THE FILESYSTEM 199

Reading from the Filesystem 200

The File and FileStream Classes 200

Creating a Files Explorer App Example 203

Modifying Files and Filesystems 216

Creating New Files and Directories 216

Utilizing Browse Dialogs 229

Opening a Single File 230

Opening Multiple Files 230

Saving a Single File to a Location 236

Summary 237

CHAPTER 8: WORKING WITH DATA 239

Detecting Changes in Network Availability 239

Retrieving Data with URLRequest 240

Monitoring the URLRequest Object 240

Creating the Maintaining Data App Example 241

Using SQLite for Storing Data 247

Creating a SQLite Database 248

Summary 286

CHAPTER 9: WORKING WITH AUDIO AND VIDEO 289

Introducing the Open Source Media Framework 289

Creating a URLResource Object 290

Creating a MediaElement Object 291

Media Traits 292

Using the MediaTraitType Class to Identify Traits 293

Using the MediaPlayer to Play Media Elements 294

Using the MediaPlayerSprite Class to Play Media Resources 297

Handling Trait Events 298

Using an AudioEvent Object 298

Using the Flex OSMF Wrapper 300

Using the VideoPlayer Component 300

Creating a MediaPlayer Example 301

Summary 313

CHAPTER 10: UTILIZING DEVICE FEATURES 315

Using the Device's Camera 315

Using the CameraUI Class 316

Creating a Camera App Example 316

Capturing Sound Using the Device's Microphone 323

Using the Microphone Class 323

Using the SampleDataEvent Class 324

Creating a Microphone App Example 326

Utilizing the Device's Web Controller 336

Using the StageWebView Class 336

Creating a Browser App Example 338

Utilizing the Device's Geolocation Sensor 346

Using the Geolocation Class 346

Using the GeolocationEvent Class 347

Creating a Geolocation App Example 348

Summary 355

INDEX 359

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)