Adobe is changing the world through digital experiences. Our creative, marketing and document solutions empower everyone — from emerging artists to global brands — to bring digital creations to life and deliver them to the right person
at the right moment for the best results.

Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change.Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.

Requirements

Prerequisite knowledge

User level

Required products

Sample files

Introduction

Modern day technology presents several unique uses for today’s advanced smart phones. Adobe’s AIR 15.0 offers a restructured AIR Gamepad API that extends the use of Android devices as game controllers and second-screen interfaces. You can use the AIR Gamepad API to connect Flash-based browser applications to a paired Android device running the AIR runtime application.

With the AIR Gamepad API you can:

Connect to an AIR runtime application and load the second-screen content to the AIR runtime application’s Gamepad view.

Provide multi player support for your games. This means that more than one device can be paired with the Flash-based browser game. (Introduced in 15.0 beta).

To download the SWC file, go to AIR 15.0 Beta and download the AIR SDK. The SWC file is located at AIR SDK\frameworks\libs\gamepad.swc.

See the API documentation for a detailed description of the API and its applications.

Working with the Gamepad API

To begin setting up a connection between the game application and the android device:

Create an AIRGamepad object using the getGamepad(gamepadID:String) static method of the AIRGamepad class.

Call the connect(stage:Stage, publisher:String,applicationURL:String) function of the AIRGamepad class.

On calling the connect() function from the Flash Player application, the user is prompted for a PIN.
The PIN is the alphanumeric string displayed on the AIR Gamepad screen on the Android device. The PIN is required to establish a connection with the Android device running the AIR runtime application. See Figure 1.

Figure 1: User prompt for PIN when the Flash Player game is launched in a browser and the connect() function is called.

In order to complete the connection from the game application to the Android device the user needs to:

1. Install the Adobe AIR runtime application on the Android device from AIR SDK\runtimes\air\android\device\Runtime.apk, if not already installed.

2. Launch the Adobe AIR runtime application.

3. Shake the device. The AIR Gamepad screen is displayed in the AIR runtime application, with a PIN. See Figure 2.

Figure 2: The AIR Gamepad screen shown by AIR runtime App on Android device

4. Enter the PIN in browser pop-up and click Connect.

Note: Both the Android device and the desktop computer need to be on the same internet network to be able to connect through the AIR Gamepad APIs.

Call drawImage(encodedImage:ByteArray) of the AIRGamepad class as soon as the connection between the game application and the android device has been established. This will ensure that that the skin is displayed immediately on the Android device’s application screen and the user can begin to control the Flash-based browser game from the Android device. See Figure 3 for an example of the skin displayed for the Flash-based game, HungryHero.

To download the swc file go to AIR 15.0 Beta and download the AIR SDK. The SWC file is located at AIR SDK\frameworks\libs\gamepad.swc.

Figure 3: HungryHero skin applied to the AIR Gamepad on Android device

You can only use images in the JPEG format for the Gamepad skin. The DRAW_ERROR error occurs when any format other than JPEG is used.

Note: Only the rotated-left landscape orientation is supported for Gamepad on Android devices, which is also applicable to the skin.

When a connection between the game application and the android device is successfully established and the skin is applied, the user can begin to use the Android device as a game controller.

HungryHero is an example of a Flash-based game that uses the Gamepad API. Accelerometer events are fetched from the Android device to decide the movements of HungryHero. The Android device vibrates when HungryHero collides with objects or eats food. The vibrate(duration:int) function of the AIRGamepad class is used to vibrate the device. You can also fetch gesture and touch events and take suitable action.

Where to go from here

You can try some of our Gamepad samples: HungryHero and ModelViewer. The source file for HungryHero is attached with this article.