Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [6]

By Root 2554 0
this dimension may seem large for a small device. Chapter 5, which covers screen resolution, will clarify this point.

Create the movie’s document class by opening the Properties panel and clicking on the pencil icon to the right of the Class field. Leave the default selection at Flash Professional and enter the class name Main.

Using Flash Builder


When using Flash Builder, two mobile options are offered. Go to File→New→Flex Mobile Project or File→New→ActionScript Mobile Project. Use Flex Mobile if you want to use the Flex framework. Use ActionScript Mobile for pure ActionScript only. For our application, choose the latter. Give it a project name of first. Leave the setting as the default SDK, and click Next.

Creating the Application Descriptor

The application descriptor is an external XML file that is bundled with your .swf file during packaging. The application descriptor file is generated automatically, but you can modify the default settings.

The application descriptor contains the application’s settings, such as its screen orientation. It also includes selected permissions. Permissions are set for some specific device functionality, such as GPS. We will review the application descriptor document in detail in Chapter 4.

Using Flash Professional


To edit the application descriptor in Flash Professional, follow these steps:

From the IDE, go to File→AIR Android settings.

Under the General tab, keep Portrait selected under Aspect Ratio, and then select “Full screen”.

Under the Permissions tab, select Internet.

Click OK.

Using Flash Builder


To edit the application descriptor in Flash Builder, follow these steps:

Under Mobile Settings→Target platforms, select Google Android.

Under Permissions, select Internet.

Under Application Settings, select Full Screen and deselect “Automatically reorient”.

Select Next.

Change the Main application file to Main.as.

Click Finish.

Writing the Code

For this exercise, we will draw three clickable sprites: one to make a phone call, one to send a text message, and one to send an email. Figure 2-2 shows our application and three native applications launched upon interactivity.

Figure 2-2. Left to right: our application with three buttons—one for calling, one for texting, and one for emailing—and the native applications launched based on the various choices

An AIR application cannot call, send a text message, or send an email directly, but it can invoke the native applications dedicated to these tasks and pass arguments such as the phone number or email address.

WARNING

The URI scheme is a way to include small data items inline. AIR passes the argument to the Android system according to the official tel, sms, and email URI schemes. If the argument contains invalid characters or spaces, the command will be ignored. Valid characters are digits, dots, and the plus sign (+). Android currently does not support multiple numbers or a body argument for a text message, but it does support multiple emails and a body argument for an email.

If more than one application has a custom URI, the choices are represented in a menu. This is the case with mailto, as demonstrated in Figure 2-2, with both native email and Gmail applications.

Note that a mouse event works on a multitouch device as though it were a single-touch device.

Using Flash Professional


If you are using Flash Professional, add the following code to the Document class named Main, created earlier:

package {

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.net.URLRequest;

import flash.net.navigateToURL;

public class Main extends Sprite {

public function Main() {

// create the three sprites and their listeners

var callButton:Sprite = createSprite(0xFF3300, 140, 150);

callButton.addEventListener(MouseEvent.CLICK, callMe);

addChild(callButton);

var textButton:Sprite = createSprite(0x0099FF, 140, 350);

textButton.addEventListener(MouseEvent.CLICK, textMe);

addChild(textButton);

var mailButton:Sprite = createSprite(0x00FF11, 140, 550);

Return Main Page Previous Page Next Page

®Online Book Reader