The New Butt-Saving Feature in Flash CS5.5
Auto Save

I'm proud to say that I'm one of those CMD+S guys. I save my work on every line of code and on every step I take while going through an animation in Flash Professional. Sometimes in Flash, when the file is too big, the saving process can take up to 2 seconds or something, which can be very distracting (especially when debugging) so I don't save my work unless I really need to. I remember one day I paid the consequences when Flash crashed (yeah it does!) and I had to re-do almost the entire project from the beginning.

Another common fact is there are people that save their work when they finish it, just because Flash "reminds" them they could save the file before quitting the application, but that's another story.

For the mentioned cases, a new nifty feature comes to rescue in Flash CS5.5, which I think it is a very important addition in this new version. The auto save feature. Set it to 1 minute and you are good to go.

I'm done with this.
Open Source is your friend

There is a lot to say when it comes to open source. The first, most common thing is you’d get plenty of collaboration and support from other experienced programmers, especially if your piece of code is readable and useful enough. Keeping your code private is not always a good idea. If you do not intend to monetize your software, why not keeping it available to others to develop and contribute to its success? In a way, most of the free, closed source software out there, are not updated as often as the open ones. This mostly happens when the developer is a single individual and the idea that he isn’t earning a penny for the hard work he does can make him lose the enthusiasm. Others are so lucky that their work is quickly approved by the audience, starting to become so popular that the idea of giving it for free can turn them into some materialistic geeks.

If you don’t feel too much excited about your (free) idea anymore, someone else might definitely be your source of (re)motivation. Worst case scenario, is you don’t feel you can maintain your software anymore and the result is your idea will be buried somewhere along your efforts, or someone else will eventually adopt it and grow up.

Thank God, I had enough motivation in the last period that I started an open source, generic AS3 framework which I develop within my overnight stays in front of my computer – but that’s another story that I’ll tell you later.

AIR applications for Android with Flash Builder 4 (Part 2): Emulator

In this part, I'm going to show you how to set up an Android Emulator, so you can test your AIR applications on it, in case you don't have a real device. If you have the Android SDK installed on your computer correctly, you might go directly to the steps below, if not, I highly recommend to follow the Android SDK setup instructions on part 1 of this article first.

Open your terminal or cmd window, and write:

$ android

This will open the Android SDK manager utility. This utility let's you update the SDK and create AVDs for your emulator. AVD stands for Android Virtual Device and basically, it is the system image that runs inside your android emulator.

At first you will see a list of the available AVD under the Virtual Devices menu. If you never created an AVD before you should see an empty list. In this case you should create an AVD, but first you would need to install the latest Android SDK package. To do that go to Setting, and check the first check box "force https://... sources to be fetched using http://...". After that go to Available Packages, click refresh and wait until the list is populated.

Check SDK Platform Android 2.2, API 8, revision 2. You might also check for later revisions if available and even select other versions at the same time. Once you have chosen these, install them by clicking the Install Selected button and wait for it to download the packages and install it. This might take a few minutes based on your download speed.

After that, return to Virtual Devices and press new to create a new AVD. Chose the AVD name of your choice, select the Android version from the drop down menu and you are good to go. You can also set the capacity of a virtual SD card, screen resolution and hardware options. Now click on Create AVD. After that you should see your new AVD listed in there. Select it and click the Start button. Now the Android Emulator should start and it will load the AVD you just created. It will take a while so be patient until it starts up. Once started, you will see the Froyo home screen running inside the emulator window. Feel free to play with it. Now you officially own a virtual Android phone, fully capable to run your awesome AIR applications.

Now, of course, you will have to install the AIR runtime for Android 2.5 (the version for the emulator) into the emulator in order to test your applications.

Update: To test your app on the Android Emulator, you should convert your application to an APK that it can understand, so while converting, in the adt command you should specify the target as "apk-emulator". So, if your application is called Main, the adt command should be:

$ sudo adt -package -target apk-emulator -storetype pkcs12 
  -keystore cert.p12 Main.apk Main-app.xml Main.swf

Of course use sudo only if you're working on a Mac.

Open Terminal or a cmd window, cd into the apk file directory and assuming the file is named "air.apk" write:

$ adb install air.apk

You should see a "success" message when successfully installed. Now try to install the demo application we created in the first part of this tutorial and test it. It should work exactly as expected.

Now you can test your AIR applications even if you don't have a real Android device.

Build AIR applications for Android with Flash Builder 4 (Part 1)

UPDATE: The application descriptor file has an additional tag — "versionNumber", which is required in order to export a native .apk file.

In my previous post, I showed how to build an Android AIR application in Flash CS5, and how to deploy it on an Android device. In this post I will show you how to create an Android application using Flash builder 4. If you read my previous post you should have already downloaded the required SKDs (AIR 2.5 for Android and Android SDK).

At this point, what you need to do, is to update the AIR version inside your Flex SDK, to AIR 2.5, which is the version you will have to use in order to compile apps for android. You can find your Flex SDK inside your Flash Builder 4 installation folder (Windows: Program Files/Adobe/Adobe Flash Builder 4/sdks/), (Mac: /Applications/Adobe Flash Builder 4/sdks/). To do this, check "How to overlay AIR for use with the Flex SDK".

Now that your SDK is ready, open Flash Builder and create a new Flex Project. Note that in this project we will need to use the Flex SDK we just set up. As "Application type" choose "Desktop", and press Next, you can leave the output folder as is. Now, we need to use pure ActionScript in this project so we won't use mxml files. So now press the next button again, and you will see the last project wizard dialogue. Give a look into the Main application file field. It is specifying an mxml file, but since we are going to use pure ActionScript, we need to change the extension to .as. So if the application file is FlashBuilderAndroidDemo.mxml, it will have to be FlashBuilderAndroidDemo.as (see the image below).

Now press finish and here you go... You have got your application ActionScript class ready to be edited.

Now create a TextField instance and put it on the stage. Note that in an ordinary AIR application you should create a NativeWindow if you are using this workflow, but in this case, since you are developing for an Android phone, you will just extend the Sprite Class (as it were a Flash Player project). However keep in mind that you might set the scaleMode of your stage to NO_SCALE (if you need to).

package {
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class FlashBuilderAndroidDemo extends Sprite {
		
		public function FlashBuilderAndroidDemo() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var tf:TextField = new TextField();
			var ts:TextFormat = new TextFormat();
			
			ts.size = 20;
			tf.defaultTextFormat = ts;
			
			tf.border = true;
			tf.x = 50;
			tf.y = 50;
			tf.width = 400;
			tf.height = 40;
			tf.text = "Tap here to input";
			tf.type = TextFieldType.INPUT;
			addChild(tf);
		}
	}
}

Here you are. Now what you need to do, is to install the application on your device or on an Android Emulator. I will explain how to deploy application on emulators in the next part of this article, for now make sure that your device is plugged to your computer's USB port and make sure it is read by writing the following code to the command line:

$ adb devices

You should now get the device ID in your command line screen. Now you will have to convert the SWF file you created into a native Android application (.apk file). So cd into the "bin-debug" directory of this project and write:

$ sudo adt -package -target apk -storetype pkcs12 -keystore cert.p12 FlashBuilderAndroidDemo.apk
  FlashBuilderAndroidDemo-app.xml FlashBuilderAndroidDemo.swf

Note: use sudo only if you are using a mac.

As you can see I am passing to the -keystore parameter a self-signed certificate file name — in this case cert.p12 was created using Flash Builder in the same way you would do as you were creating an ordinary AIR app for desktop — after that the name of the output .apk file, the application descriptor xml file and finally the .swf file to convert. You will be asked to input a password which is the certificate password (if you used sudo, you will be prompted first for the user password). If everything went OK, you should see an .apk file in your bin-debug directory. Let's install it on the device:

$ adb install FlashBuilderAndroidDemo.apks

You should get a success message on your command line screen. Now grab your Android device and start the application. You should see the TextField we created. Tap it. Since it is of type "input" you should see the android soft keyboard popping up from the bottom of your screen.

Stay tuned for part 2, where I will show you how to deploy AIR apps on an emulator, for who doesn't have a device yet.

Good Luck!

Getting started with AIR and Android

If you don't know yet, you can publish your AS3 projects to run as Native Applications (.apk) on the Android OS (netbooks and phones). This article will show you how to use Adobe Flash CS5 Professional to create an application that runs on your Android device in 5 minutes.

Prerequisites:
  • Flash CS5 Professional (Download trial here)
  • AIR 2.5 runtime for Android Eclair or Froyo
  • AIR 2.5 SDK
  • The AIR for Android extension for Flash CS5
  • The Android SDK (download here)
  • An Android device (to test and debug your application on it, but it is not a must)

The AIR runtime, SDK for Android and the Android project extension for Flash CS5, are available on the Adobe Prerelease Program for now, so you will have to sign up for it and you can do it here. Once you're in you will be able to download them immediately.

Once you get the Android extension for Flash Professional, install it so you will be able to publish your creations as an Android Native application.

Now that you have these things set up, you can go ahead and open Flash CS5 Professional.

As you open it, you'll find what's on the image above. You'd go for the "AIR for Android" Template that now appears magically because of the extension you've just installed (or previously installed), which basically is an ActionScript 3 project but with AIR for Android publishing settings.

Now you've got a stage with generally the same dimensions of an Android device, however you are free to change the stage dimensions as it might vary from device to device. Here you go:

As you can see in this image, there is an additional edit button for "AIR Android Settings". We will give a closer look to it later on.

Now let's create some cool content on our stage. Some animation, some code... You can do whatever you want as it were an ordinary AIR application, just keep in mind that you will have to do some optimization as it is going to run on a phone and not a computer (of course you'll do). For me, I'm just gonna put some cool "Hello World" TextField in the center of the stage, for the purposes of this demo.

You might want to add some Mouse Events, some glow effects or whatever you want. Once you are done test your project by hitting ctrl+enter (cmd+enter in Mac) and here you go your first Android content is living inside a SWF file wrapped inside the Flash Player. But it is not enough yet is it? We need to deploy this content as a native application on our Android device. So now connect your phone to your computer as I'm gonna show you some cool stuff.

Now select the stage and open the properties panel. Next to the "AIR Android Settings" click the "edit" button and you'll see this panel.

Fill the fields as it is shown in the image.

The output file is the application you are going to deploy on the Android device. The application name is the name of the application (great explanation) and the app ID is an ID that the device recognize as a single application, which means if you install another app with the same ID of a previously installed app, it will replace it. Then go for the rest which is self explanatory.

Now go to the deployment tab. Where you will select a signing certificate (or create a new one) and enter its password, just like you would do in an ordinary AIR application for desktop.

Now we are going to debug the app directly on the device (in my case a Nexus One) so select "Device Debugging", check the other the other two self explanatory options.

The last thing to do is to select the path of the adb file that you can find in the Android SDK I've been talking about above in the prerequisites. Click OK. We are not done yet! In order to debug on the device and receive console messages, we need to enable debugging on the device itself. So on the device go to "Settings > Applications > Development" and check "USB Debugging" and "Stay awake" (which won't let your device auto lock). Note these settings are for Eclair and Froyo versions of Android (2.1 and 2.2).

Once you do this, on Flash go to the File menu and click on "Publish", if everything is set right, you should get your application installed and running on the device. Of course you can test the minimal things on Device Central or just through the Flash Player instead of publishing to the phone every now and then. I'd personally  test on the device only device related actions such as dealing with the phone's file system, touch activities etc.

And that's it for now. Soon I'll be posting how to do the same thing using Flash Builder with a Pure ActionScript 3 project.

Enjoy!