Book Review: Flash Development for Android Cookbook

September 22nd, 2011 by Adrian

Flash Development for Android Cookbook front cover

Title: Flash Development for Android Cookbook
Author: Joseph Labrecque
Publisher: Packt Publishing
Released: June 2011
Website link: http://goo.gl/icJsk
Amazon link: http://goo.gl/TGBv5

For any Flash or Flex developer looking to create applications for mobile (in particular Android ones) then this is a great book to have on your desk! Weighing in at 372 pages, there is a lot of content in there just waiting for you to try out and play with.

First things first, this is a Cookbook. It’s not a reference title listing every single API and documenting every single class available. Though to be honest, it seems to cover most of the new AIR for Android features. The idea behind a Cookbook is to provide you with a selection of ‘recipes’ or common tasks, and then explain how to go about solving them in a clear and concise way. This book does this brilliantly. It is the sort of book you can dib into when you have a specific thing to get done in your app and you’re not sure where to start. Having said that, I basically read it from cover to cover, and still found it very informative and enjoyable.

The book is broken up into the following 11 chapters …

  • Chapter 1: Getting Ready to Work with Android: Development Environment and Project Setup (10 recipes)
  • Chapter 2: Interaction Experience: Multitouch, Gestures, and Other Input (13 recipes)
  • Chapter 3: Movement through Space: Accelerometer and Geolocation Sensors (9 recipes)
  • Chapter 4: Visual and Audio Input: Camera and Microphone Access (6 recipes)
  • Chapter 5: Rich Media Presentation: Working with Images, Video, and Audio (7 recipes)
  • Chapter 6: Structural Adaptation: Handling Device Layout and Scaling (12 recipes)
  • Chapter 7: Native Interaction: StageWebView and URI Handlers (10 recipes)
  • Chapter 8: Abundant Access: File System and Local Database (7 recipes)
  • Chapter 9: Manifest Assurance: Security and Android Permissions (6 recipes)
  • Chapter 10: Avoiding Problems: Debugging and Resource Considerations (6 recipes)
  • Chapter 11: Final Considerations: Application Compilation and Distribution (10 recipes)

All these chapter are equally important and cover a wide range of features, but which ones you’ll actually need to use will depend on your project and what you are trying to achieve. Although the title of this book specifies Android, most of the code in this book will work equally well on iOS devices and the BlackBerry PlayBook. That’s the joy of developing using ActionScript and AIR! :-)

I was particularly pleased to see that nearly all the code examples were IDE agnostic and didn’t tie you in to the Flex framework. They concentrated on using pure ActionScript in whatever IDE you feel comfortable working in. In fact, Joseph even went to the trouble of explaining any IDE specific stuff using example in Flash Pro CS5.5, Flash Builder 4.5 and FDT 4.1.

Once you have had a flick through at some of the examples it quickly becomes clear that Adobe have done a really good job at providing a consistent and logical API for achieving all these new mobile specific things. And this book does a great job of demystifying it all.

My one criticism would be that there is quite a lot of repetitive code (about 14 lines) in each example, where Joseph sets up an output textfield (and accompanying textformat) for demonstration purposes. But I guess I noticed it more because I was reading the book straight through (not how it was intended to be read). At least this way, each ‘recipe’ or example is self contained and provides everything you need to get you up and running easily.

I did notice a few errors here and there (code and layout), but nothing too serious that would cause you issues.

I’d thoroughly recommend this title to anyone who is interested in creating mobile apps for either Android, iOS or PlayBook using AIR and ActionScript.

Sample Chaper
Chapter 4 - Visual and Audio Input: Camera and Microphone Access can be downloaded as a free PDF file here.

Related books by other authors and publishers include:

Posted in AIR, Android, Books, Mobile | No Comments »

AIR 2.5 for Android now available on the Android Marketplace

October 8th, 2010 by Adrian

AIR 2.5 for Android

AIR 2.5 for Android has just been formally released and is now available on the Android Marketplace. Which means end-users can now get the runtime and then install your apps created with AIR. Users will need to be running Android 2.2 (Froyo) to see it in the Marketplace.

Ryan Stewart has a blog post with some info on publishing your apps to the marketplace.

Here are some other useful links to help you get started with AIR for Android …

Luckily my iPhone contract has just expired. Android here I come! :-)

Adobe AIR for Android Install Screen

Posted in AIR, Android, Mobile | No Comments »

My Flash On The Beach Schedule

September 26th, 2010 by Adrian

Flash On The Beach 2010

Well, it’s that time of the year again where the great Flashers from all around The World decend on Brighton, England. That’s right folks, Flash On The Beach is upon us once again. I’m really looking forward to it again this year (no different to any previous year really). Looking forward to coming away feeling enthused, inspired, educated and though provoked.

John Davey (the conference organiser) has only gone and made choosing what to see even harder this year by including a fourth track. Thanks John ;¬) Like it wasn’t hard enough trying to pick what to see (and what to miss).

At this moment in time, I have penciled in the following schedule …

Day 1: Monday 27th September 2010

Day 2: Tuesday 28th September 2010

Day 3: Wednesday 29th September 2010

Posted in Conferences and Events | No Comments »

Adobe AIR Runtime Version Checker

December 11th, 2009 by Adrian

Version Checker

Have you ever wondered what version of the Adobe AIR Runtime you have installed on your computer? Well, if you have then you’ve probably found it difficult to find out. Luckily Jason Madsen has built a simple AIR App that will tell you. It does what it says on the tin. Very handy!

BTW, if you want to know what version of the Flash Player you have installed in your browser just visit www.playerversion.com to find out. Thanks Aral.

Posted in Adobe, AIR, Tool | 1 Comment »

Printing a PDF document from AIR without displaying it or the control bar (using PDF cross-scripting)

October 6th, 2009 by Adrian

Recently I had a project where I needed to allow the user to print out a PDF document from my AIR application, but I really didn’t need the user to actually view the document first and I didn’t want to display the default PDF control bar. I needed some way to send the PDF file to the printer directly from ActionScript. Enter PDF cross-scripting and Acrobat JavaScript. The following information should help you achieve the same result (note you need to have access to a copy of Adobe Acrobat Pro to add the JavaScript code to your PDF file).

There are several steps required for this to work …

  1. Open the PDF document you want to print in Adobe Acrobat Pro.
  2. Add the JavaScript code to your document and save it.
  3. Create an HTML page that contains a JavaScript function and embed the PDF document.
  4. In your Flash (or Flex) file add a button that prompts the user to print the document.
  5. Add the ActionScript 3.0 code that communicates with the HTML page you created in step 3.
  6. Publish your AIR file (making sure you include the HTML and PDF files).
  7. Test your AIR app.

Here is a copy of the PDF file I am printing in the following example.

Right, let’s explain each of the above steps in more detail.

Step 1

I presume you already have a PDF file prepared which you wish to print. Open this file up in Adobe Acrobat Pro. I’m pretty sure this works in version 7.0 and onwards.

Step 2

Open the ‘JavaScript Functions’ dialog box in Adobe Acrobat Pro by going to ‘Advanced’ > ‘Document Processing’ > ‘Document JavaScripts’.

Acrobat Document JavaScript Menu

Enter ‘myOnMessage’ in to the textfield and click on the ‘Add…’ button.

Acrobat JavaScript Functions

Then enter the following JavaScript code in to the window and click on the ‘OK’ button.

JavaScript Editor

function myOnMessage(aMessage)
{
      if (aMessage.length==1) {
            switch(aMessage[0])
            {
                  case "Print":
                        //app.alert("Trying to print PDF");
                        print({
                              bUI: true,
                              bSilent: false,
                              bShrinkToFit: true
                        });
                        break;
                  default:
                        app.alert("Unknown message: " + aMessage[0]);
             }
      }
      else
      {
            app.alert("Message from hostContainer: \n" + aMessage);
      }
}

var msgHandlerObject = new Object();
msgHandlerObject.onMessage = myOnMessage;
msgHandlerObject.onError = myOnError;
msgHandlerObject.onDisclose = myOnDisclose;

function myOnDisclose(cURL,cDocumentURL)
{
      return true;
}

function myOnError(error, aMessage)
{
      app.alert(error);
}

this.hostContainer.messageHandler = msgHandlerObject;

Then remember to re-save your PDF file.

Step 3

Create a blank HTML file and save it next to the PDF file. Then add the following code …

<html>
    <head>
    <title>Load PDF</title>
    <script>
        function callPdfFunctionFromJavascript(arg)
        {
            pdfObject = document.getElementById("PDFObj");
            try {
                 pdfObject.postMessage([arg]);
            }
            catch (e)
            {
                alert( "Error: \n name = " + e.name + "\n message = " + e.message );
            }
        }
    </script>
    </head>
    <body>
        <object id="PDFObj" data="document.pdf" type="application/pdf" width="800" height="600"/>
    </body>
</html>

Step 4

For this example I’m using Flash CS3. Create a movieclip on stage that acts as a button prompting the user to print the PDF document. Give the button instance the name of ‘button’.

Step 5

In this example I have put all the ActionScript code into the document class. The code looks like this …

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.html.HTMLLoader;
    import flash.html.HTMLPDFCapability;
    import flash.net.URLRequest;

    public class PrintPdfFromAir extends MovieClip
    {
       
        private var _htmlLoader:HTMLLoader;

        public function PrintPdfFromAir():void
        {
            button.mouseEnabled = false;
            button.alpha = 0.3;
            button.buttonMode = true;
            button.addEventListener(MouseEvent.CLICK, onButtonClick);
           
            trace("HTMLLoader.pdfCapability: "+HTMLLoader.pdfCapability);
           
            if (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK) {
                _htmlLoader = new HTMLLoader();
                _htmlLoader.addEventListener(Event.COMPLETE, onHtmlLoader_COMPLETE);
                var urlRequest:URLRequest = new URLRequest("load_pdf.html");
                _htmlLoader.load(urlRequest);
                addChild(_htmlLoader);
            }
        }
       
        private function onHtmlLoader_COMPLETE(event:Event):void
        {
            button.alpha = 1;
            button.mouseEnabled = true;
        }
       
        private function onButtonClick(event:MouseEvent):void
        {
            _htmlLoader.window.callPdfFunctionFromJavascript('Print');
        }

    }

}

Basically, we disable to button straight away and add a CLICK event listener. We then check the ‘HTMLLoader.pdfCapability’ property to see if the user has Adobe Reader 8.1 or greater installed on their system. If it equals ‘HTMLPDFCapability.STATUS_OK’ then we can continue. We then create a new instance of the HTMLLoader class, add a listener for the COMPLETE event. We then create an instance of the URLRequest class passing it the name of the HTML file we created in step 3. Next we call the ‘load’ method on our _htmlLoader instance, passing it the urlRequest instance. Then we add the _htmlLoader instance to the stage using addChild.

Normally, when you want to actually display the PDF file on screen, you also need to specify the width and height of the HTMLLoader instance. But in our case we don’t want to actually display it to the user. You may be wondering why we add it to the display list using addChild if we don’t want it to be visible. But I have found that it doesn’t work if you don’t add it to the display list. Not specifying the width and height also means it is not visible (which is what we want on this occasion).

Now we just have the two event handlers to write. The event handler for the HTMLLoader COMPLETE event just makes the button on screen active. We didn’t want the user to be able to click it before the COMPLETE event was fired.

The event handler for the button CLICK event calls the JavaScript function inside the HTML page, which we wrote in step 3.

Step 6

Now you are ready to publish the SWF file and then package it up as an AIR app in the usual way. The important thing to remember is to include the two external files (HTML and PDF) in the AIR Settings dialog box.

Include files

You can create a self-signed certificate for the purposes of testing. I have included my self-signed certificate with the source files (the password is ’1234′) which you can use if you wish, or you could just create a new one.

Step 7

Once you have exported your AIR file it is a good idea to test it on a few different computers to make sure it works properly. Try it on a machine that doesn’t have Adobe Reader installed, or one that has an older version (< 8.1).

Download example AIR app

Download the example AIR file

Click here to download the example AIR file

Download source files

Download ZIP file containing source files

You can download a ZIP file containing my example source files from here.

Useful links

Here are some other blog posts and articles I found useful …

Posted in ActionScript 3.0, AIR, Sample Code | 10 Comments »

101 Adobe AIR Resources

April 24th, 2008 by Adrian

Adobe AIR Logo

Jason Bartholme has posted a good list of 101 Adobe AIR Resources on his blog. He has broken the links down in to the following categories …

  • Getting Started
  • Application Collections
  • Articles
  • Bloggers
  • Language-Specific Integration
  • Popular Applications
  • Resources
  • Third Party Integration
  • Tutorials

Posted in AIR | 1 Comment »

Adobe AIR Stopwatch

April 15th, 2008 by Adrian

Stopwatch

I’ve just built a handy stopwatch Adobe AIR app. Basically, it is a simple timer with Hrs:Mins:Secs.Ms, Start, Pause, Continue and Reset. The number of times I have needed a simple timer like this and havn’t had one, so I decided to build one myself. I’ve used Adobe AIR so that it installs on your system like any other application and is also cross-platform.

Here is the Flash movie of it …

And you can install the AIR file from here and here is a version that uses SWFObject to embed the install badge.

The source files are available here.

Adobe AIR Marketplace

It is also available for download from the Adobe AIR Marketplace.

UPDATE 26/08/2008: Simple Stopwatch 1.0 has been selected by Softpedia for inclusion on their website.

Posted in ActionScript 3.0, AIR | 3 Comments »

Adobe Flex 3 and AIR Released

February 25th, 2008 by Adrian

Adobe Flex 3 and AIR

Today Adobe officially released Flex 3 and AIR (Adobe Integrated Runtime) for the desktop. I won’t say too much about them here, as there is already plenty of info out there in the blogosphere. If you want to find out more, follow the links provided.

Posted in Adobe, AIR, Flex | No Comments »

AdobeAir Website

February 19th, 2008 by Adrian

MasterCool By AdobeAir

I just did a quick Google search for “adobe air” and the sixth result was this website (www.adobeair.com) for air conditioning units. I did a quick Whois Lookup on the domain and it looks like they are genuine and have had that domain name registered since 1999. Just a coincidence?

Posted in Adobe, AIR | 1 Comment »

15 Things to look in to during 2008

January 31st, 2008 by Adrian

Here is a list of things I want to look in to during 2008. If there is anything you think I should check out but have missed off this list then let me know.

  1. Papervision3D
  2. Tweener
  3. TweenLite
  4. Go (Go ActionScript Animation Platform)
  5. KitchenSync
  6. Xray (The AdminTool)
  7. AS3 Bulk Loader Library
  8. SWX: SWF Data Format
  9. Adobe Flex 2 & 3
  10. Adobe AIR
  11. Eclipse and FDT 3.0
  12. Cairngorm
  13. PureMVC
  14. ActionScript 3.0
  15. SWFAddress

Not necessarily in that order. Wish me luck!

Posted in ActionScript 3.0, Adobe, AIR, Flash, Flex, Papervision 3D | 2 Comments »

Location of Flash Shared Object (SOL) files

January 30th, 2008 by Adrian

If you are anything like me, then when you need to find your Flash Shared Object (SOL) files, you can never find them on your computer. Well, just as a reminder, they can be found here on a Windows XP PC …

C:\Documents and Settings\<username>\Application Data\Macromedia\
Flash Player\#SharedObjects\<random string>\<domain>\
<path from webserver>\<filename>.sol

on a Windows 7 PC they are stored here …

C:\Users\<username>\AppData\Roaming\Macromedia\Flash Player\
#SharedObjects\<random string>\<domain>\<path from webserver>\
<filename>.sol

and on a Mac they can be found here …

Macintosh HD:Users:<username>:Library:Preferences:Macromedia:
Flash Player:#SharedObjects:<random string>:<domain>:
<path from webserver>\<filename>.sol

I also recently noticed that the path to data saved from Adobe AIR apps is stored here on a PC …

C:\Documents and Settings\<username>\Application Data\
<AIR App Reverse Domain Name>\Local Store\#SharedObjects\
<flashname>.swf\<filename>.sol

and on a Mac they can be found here …

Macintosh HD:Users:<username>:Library:Preferences:
<AIR App Reverse Domain Name>:Local Store:#SharedObjects:
<flashname>.swf\<filename>.sol

NOTE: On Mac OS X 10.7 (Lion) and above (Mountain Lion etc) the Library folder is hidden. To make it visible you need to go to Finder, select the ‘Go’ menu from the top and then hold down the Option (alt) key. The ‘Library’ item will then appear so you can click on it. The Library folder will then open and you can then click into the ‘Preferences’ folder. Also note that Shared Objects from AIR apps are stored directly in this ‘Preferences’ folder using their reverse domain app ID. Shared Objects from a browser based SWF are stored in …

Macintosh HD:Users:<username>:Library:Preferences:Macromedia:
Flash Player:#SharedObjects:<random string>:<domain>:
<path from webserver>\<filename>.sol

Hope this is of some help, and will save you a bit of time trying to find them.

There are also a few useful tools out there that will allow you to check (and modify) the contents of SOL files. Try ASV SOL Viewer and Editor, SolVE: Local Shared Object Viewer/Editor or SOLReader.

Posted in AIR, Flash | 1 Comment »

O’Reilly’s InsideRIA launched

January 29th, 2008 by Adrian

InsideRIA

Last week O’Reilly launched the InsideRIA website, a portal/blog for Rich Internet Application developers around the world. It looks like it is going to be a great resource and it currently has articles written by respected people such as Colin Moock, Rich TretolaTony Hillerson, David Tucker, Tony MacDonellAndrew TriceAndre Charland, Jonathan Snook and Raymond Camden.

The also have an InsideRIA Atom feed (which I have added to my Google homepage).

Posted in ActionScript 3.0, Adobe, AIR, Flash, Flex | No Comments »

Adobe on AIR Bus Tour is heading to Europe

January 28th, 2008 by Adrian

on AIR

The Adobe on AIR Bus Tour is coming to Europe (minus the bus) this summer. At the time of writing the details (locations and dates) are still being finalised. Keep up-to-date by checking the Bus Tour Weblog and the on AIR Weblog. You can also follow the tour via video, Twitter and Flickr.

Posted in Adobe, AIR, Conferences and Events | No Comments »