Text Escaping Unescaping with AIR
For a project I worked a few months ago I needed to escape special characters used to pass some information from one point to another. Of course I used at that point the great application built by Marc called Unicode2HTML but I needed more than that. I wanted to convert also to other formats like \uXXXX or Punycode so after searching the net for a tool like that I found a very nice library built by Satorux called strutil.js.
The library actually does exactly what I wanted, it converts a character to a bunch of formats that I can use. The service Satorux has build, using this library, can be found at Text Escaping and Unescaping in JavaScript.
I decided to port this online version to an application so we can use it in offline also. This was a good project because it concluded to be my first Adobe AIR project (hope more will come).
I won’t make a tutorial on how to build an AIR app in this article because there is no point you can search the net for this kind of things and you will find dozens of great tutorials. But what I want to share with you is the application itself and the simplicity of the AUTO UPDATER Framework Adobe AIR has…
So here is the app I have made; click to install. For any kind of feedback just leave me a comment here or send me an email using the Contact page.
After reading the detailed information about how to update an AIR application I realized that this was easy as saying Scotty UPDATE ME
If need to check for a new update to my application all I need to do is to add this code in my page (HTML/Ajax version).
// instantiate an updater object
var appUpdater = new runtime.air.update.ApplicationUpdaterUI();
function checkUpdate()
{
// we set the URL for the update.xml file
appUpdater.updateURL = "http://localhost/update.xml";
//we set the event handlers for INITIALIZED nad ERROR
appUpdater.addEventListener(runtime.air.update.events.UpdateEvent.INITIALIZED, onUpdate);
appUpdater.addEventListener(runtime.flash.events.ErrorEvent.ERROR, onError);
//we can hide the dialog asking for permission for checking for a new update;
//if you want to see it just leave the default value (or set true).
appUpdater.isCheckForUpdateVisible = false;
//if isFileUpdateVisible is set to true, File Update, File No Update,
//and File Error dialog boxes will be displayed
appUpdater.isFileUpdateVisible = false;
//if isInstallUpdateVisible is set to true, the dialog box for installing the update is visible
appUpdater.isInstallUpdateVisible = false;
//we initialize the updater
appUpdater.initialize();
}
function onUpdate(event)
{
//starts the update process
appUpdater.checkNow();
}
function onError(event)
{
alert(event);
}
And on the <body> tag we just call the function:
<body onload="checkUpdate();">
Behind the scenes the flow is quite easy the checkUpdate() function reads the update.xml file and compares the information from there with the current application version (located in application.xml), if a new version is available will prompt the updater Ui asking for permission to install the new version.
The update.xml file looks like this:
<pre> <?xml version="1.0" encoding="utf-8"?> <update xmlns="http://ns.adobe.com/air/framework/update/description/1.0"> <version>0.2</version> <url>http://localhost/app.air</url> <description><![CDATA[ Version changes TEXT ]]></description> </update> </pre>
You can use this code to make an auto-updater for your Air applications every time, so great job Adobe for this nice feature.
You can leave a response, or trackback from your own site.
Leave a Reply






