Adobe AIR Runtime Version Checker

December 11th, 2009 by Adrian Parr

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 AIR, Adobe, 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 Parr

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 AIR, ActionScript 3.0, Sample Code | 6 Comments »

101 Adobe AIR Resources

April 24th, 2008 by Adrian Parr

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 Parr

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 AIR, ActionScript 3.0 | 3 Comments »

Adobe Flex 3 and AIR Released

February 25th, 2008 by Adrian Parr

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 AIR, Adobe, Flex | No Comments »

AdobeAir Website

February 19th, 2008 by Adrian Parr

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 AIR, Adobe | 1 Comment »

15 Things to look in to during 2008

January 31st, 2008 by Adrian Parr

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 AIR, ActionScript 3.0, Adobe, Flash, Flex, Papervision 3D | 2 Comments »

Location of Flash Shared Object (SOL) files

January 30th, 2008 by Adrian Parr

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 PC …

C:\Documents and Settings\<username>\Application Data\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

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 | No Comments »

O’Reilly’s InsideRIA launched

January 29th, 2008 by Adrian Parr

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 AIR, ActionScript 3.0, Adobe, Flash, Flex | No Comments »

Adobe on AIR Bus Tour is heading to Europe

January 28th, 2008 by Adrian Parr

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 AIR, Adobe, Conferences and Events | No Comments »