Posts tagged "FB"

Building Native Installers for Adobe AIR Using Burrito

There is an excellent post on quickly building native installers for Adobe AIR. Native installers are required if you are building AIR applications, which takes advantage of the extensibility options available from the native process API. The advantage is, you can start distributing your AIR-based desktop applications as native installers.

If you are using Adobe Flash Builder Burrito, you can build native AIR installers quicker than the steps mentioned in other blogs/sites.

  1. Click Project > Export Release Build…
  2. Select ‘Export and sign a native installer’ and click Next.
  3. Provide  a path to your PKCS12 certificate or create a new certificate from the interface.

That is all to it! Depending on your platform, you’ll see a native installer for your AIR application.

Isn’t this faster?

Building your first AIR-based mobile game in Burrito

The Adobe Flash Platform provides an elegant way to build, distribute, monetize, and play games on the  mobile platform. Once you learn the basics of ActionScript, Flex, and AIR, you can easily build simple to advanced games targeting various mobile devices.

Mobile games have gained immense popularity in the recent years primarily because of their ability to provide entertainment on the go. What does it mean for developers? There are numerous opportunities for game developers to produce and monetize their games on different online channels including the Android Market.

While you can use any language and tool to produce mobile games,  Flash Builder allows you to develop market-ready games with minimal effort. Moreover, Flash Builder provides a neat interface for building your game engine/levels and also allows you to debug your game on a connected device.

In this post, I’ll show you how you can build a simple Accelerometer-based game for the Android market using Adobe AIR and Flash Builder (Burrito). The objective of this game is to guide the earth ( image) towards the black hole (image) by using the accelerometer of the mobile device.

Now, if Accelerometer is available on the mobile device, you can initialize and handle the Accelerometer event as follows:

var acl:Accelerometer;
acl.addEventListener(AccelerometerEvent.UPDATE, handleACLUpdate);

private function handleACLUpdate(event:AccelerometerEvent):void{

    rollingX = (event.accelerationX * FACTOR) + (rollingX * (1-FACTOR));
    rollingY = (event.accelerationY * FACTOR) + (rollingY * (1-FACTOR));
    rollingZ = (event.accelerationZ * FACTOR) + (rollingZ * (1-FACTOR));

    earth.x = Math.round(earth.x - (rollingX*rollingSpeed));
    earth.y = Math.round(earth.y - (rollingY*rollingSpeed));

Accelerometer data obtained from the device has some degree of inaccuracy. You can use a moving average of recent data to smooth out the movement of the earth. For more information on the Accelerometer class, read the documentation.

You can move the earth by simply tilting the mobile device on any particular direction. You should also remember to align the earth back in to the stage when it moves out of screen bounds. To achieve this, we’ll use the Flex effects:

<s:Bounce id="beffect" />

<s:Move id="topbounce" target="{earth}" yBy="2" duration="100" />
<s:Move id="bottombounce" target="{earth}" yBy="-2" duration="100"   />
<s:Move id="leftbounce" target="{earth}" xBy="2" duration="100"
        easer="{beffect}" repeatCount="1"  />
<s:Move id="rightbounce" target="{earth}" xBy="-2" duration="100"
        easer="{beffect}" repeatCount="1"  />

The trick is to move the earth by a very few pixels in the opposite direction with a short animation so that the continuous Accelerometer effect on the earth image does not make the earth movement jerky. You can also vary the duration of the animation and the amount of pixels to move to achieve better smoothness.

At this point, you should read the Flex 4 documentation for more information on Flex effects.

You can use Flash Builder to create mobile views for adding the media assets. Learn more on Flex Mobile Views and Navigators. You can drag and drop images on the stage using the design view.

You need to embed the images for the effects to work.

After obtaining the Accelerometer inputs, you can choose to calculate the distance between the Black Hole image and the earth’s image. If the center points of both the images collide, raise an event to handle the collision. In our game, we increase the score. You can use the same concept to decrease the score when the earth hits any other rigid body apart from the black hole. The game play involves steering the earth to the black hole by carefully avoiding any stationary or moving objects.

I have built this simple game that will enable you to:

  • Create game levels. In this game, each View is a level.
  • Build ActionScript game engines. You can view and modify the sample code pertaining to health, score, and HUD management.
  • Understand and handle timers. Game timers control the duration of the game play. Excessive usage of timers will affect the game’s performance. Be warned!
  • Persist game data. You can serialize the game objects to the application storage directory. The sample game stores high scores for each level and supports auto saving.

Getting Started

  1. Before you begin, download and install Flash Builder Burrito.
  2. Download the Black Hole Flash Builder Project. Extract the archive to get the BlackHole.fxp file.
  3. Click File > Import Flash Builder Project and select BlackHole.fxp
  4. To run the sample game, select Run > Run. For the launch method, select ‘On device’ and click Run. Make sure that your Android device is connected to your computer through USB.

Also, in the sample game, you can drag and drop the earth in to the black hole if you get tired of using the Accelerometer. This test game is also available in the Android Market as ‘Black Hole’.

Happy Gaming!

Creating an apk File Using FlashBuilder 4.0

Using FlashBuilder 4.0, you cannot create an apk file through the GUI elements. You need to use AIR SDK commands for accomplishing this. The steps for creating an apk file is provided below:

  (The bin directory refers to the bin directory in your latest AIR SDK. Do the following after you create an SWF file.)

1. In the application descriptor file, edit the supported profiles to <supportedProfiles>mobileDevice</supportedProfiles>.

2. Create a certificate file (.pfx file).

bin\adt -certificate -cn <any-name> 1024-RSA <certificate-file-name>.pfx <password>

3. Assign the certificate to the swf file.

bin\adt -package -storetype pkcs12 -keystore <certificate-file-name>.pfx -storepass <password> <air-application-name>.air <application-descriptor>.xml <swf-file-name>.swf

This command creates a digitally signed air application.

4. Create an apk file.

bin\adt -package -target apk-emulator -storetype pkcs12 –keystore <test_cert.pfx> <name-apk>.apk <application-descriptor>.xml <swf-file-name>.swf

This command creates a valid apk file that you can install in an emulator. You need to provide the password you set in step 3.

5. Install the apk file in the emulator.

<emulator-install-dir>\tools\adb install <apk-name>