This article was originally written in English. Text in other languages was provided by machine translation.
Adobe Flash and AIR are ubiquitous platforms to develop rich internet applications. Flash is used for browser based applications and AIR is used for developing native platform applications. Both platforms have considerable support for globalization. Globalization enablement features like locale aware formatting/parsing, collation, case transforms, localization and multi-lingual text rendering are supported by both these platforms. But some more globalization features like text normalization, transliteration, Unicode character properties, encoding conversions, charset detections, Unicode string utilities etc are still missing in the Adobe AIR and Flash platforms. One of the primary reasons for not adding all these features inside the Adobe runtime platforms is the size of the software.
To overcome the size limitation issue, Adobe AIR and Flash can invoke the services of external dynamic libraries through ActionScript. There are some well known external libraries which have rich globalization support like ICU, GNU glib, Verisign IDN library to name a few. Fortunately the upcoming Adobe AIR 3.0 (now available as Adobe pre-release) has a wonderful feature called ActionScript native extensions, which is about ActionScript programming interface for a native code library like MS Windows DLL, Os X FrameWork, Android JAR or shared library or iOS static library. Please see Adobe AIR3 beta site http://labs.adobe.com/technologies/flashplatformruntimes/air3/ on how to download and take part in the Adobe AIR pre-release. Please make a note that this native extensions feature is available _only_ in Adobe AIR platform, not in the Flash platform.
In this blog, I demonstrate a sample (Download air_icu ) application to invoke ICU from an Adobe AIR application on Windows platform. Readers are reminded that this is only illustration sample software and by no means production quality software. Hence readers must exhibit discretion in using this software as it is. The sample illustrates ICU word breaking, sentence breaking, utf-conversion and Unicode character property verification.
You will need the following software to build an ICU extension for AIR platform.
- MS Visual Studio 2010 (to build AIR native extension DLL coded in C/C++)
- Adobe Flex SDK 4.5.1 (http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.5). Download this to C:Flex4.5.1.
- Adobe Air 3 Beta2 download (To build Adobe Actionscript extension) from http://labs.adobe.com/technologies/flashplatformruntimes/air3/ . Unzip this in to C:Flex4.5.1. This step overwrites the AIR related components in Flex4.5.1 sdk with latest Adobe Air3 beta2. Also keep a copy in C:air3_beta2 folder.
- The Adobe pre-release Flash runtime web site has more information, documentation and samples on how to use ActionScript extensions. The ‘product details’ tab in the http://labs.adobe.com/technologies/flashplatformruntimes/air3/ web page has a FAQ on how to join the Adobe pre-release program.
- ICU 4.8 binaries (http://site.icu-project.org/download/48). Download windows 32bit VC2010 zip. Unzip the libraries to any folder. My sample downloaded to C:icuicu4.8.1win32 folder.
1 Building ICU extension for Adobe AIR
Adobe AIR t native extensions, also known as ‘ane’ or ‘ANE’ files are archived packages. These consist of
- ActionScript wrapper classes calling into external DLLs
- The external DLLs
- XML file describing details of external DLLs
The archived ANE files are used just like SWC libraries in integrating into an AIR application. In other words, ANE file is a library and it has public ActionScript APIs.
Covering all details about the ActionScript extension is too much for this blog article, but I will explain the steps to build this sample and run. Below are the sequential steps and commands.
1.1 Building Windows AIR ICU Extension DLL
1) The AirIcuExtensionWin folder has the Visual studio solution ‘AirIcuExtension.sln’. Open this in MS VS2010.
2) The file AIRIcuExtension.cpp has the necessary code needed to interface with Adobe AIR 3 beta 2. It also has the wrapper routines calling ICU C functions.
3) This is a DLL project and the build output is AirIcuExtension.dll
1.2 Building ActionScript Library
1) Build the actionscript library using the below command.
C:Flex4.5.1bincompc.exe -source-path src -include-classes com.adobe.extensions.AirIcuExtension -external-library-path C:air3_beta2frameworkslibsairairglobal.swc -output binAirIcuExtension.swc
The file AirIcuExtension.as in the folder srccomadobeextensions has the public class AirIcuExtension which calls the ICU routines. In this sample, calling ICU sentence breaker, word breaker, normalizer, utf-conversion and Unicode character property have been illustrated.
1.3 Packaging ActionScript native extension
Open the binAirIcuExtension.swc is a zipped archive. Open it using WinRAR or WinZip program and extract the library.swf file in the swc package into the AirIcuExtension/bin folder.
The folder srcresources contains file extension.xml, AirIcuExtension.dll and ICU dlls icudt48.dll, icuuc48.dll, icuio48.dll and icuin48.dll. The file external.xml defines the external library details to AIR runtime.
For simplicity, place the AirIcuExtension.dll, ICU dlls and extension.xml files in AirIcuExtensionbin folder. All these files are packaged into a zipped archive called AiricuExtension.ane using the following command.
C:air3_beta2binadt -package -storetype pkcs12 -storepass <passwd> –keystore <AIR certificate> -tsa none -target ane AirIcuExtension.ane extension.xml -swc AirIcuExtension.swc -platform Windows-x86 library.swf AirIcuExtension.dll icudt48.dll icuin48.dll icuio48.dll icuuc48.dll
Using Adobe FlashBuilder4.x or C:air3_beta2binadt program, one can make an AIR certificate.
The output is an archive file AirIcuExtension.ane in the AirIcuExtension/bin folder.
1.4 Building the Test program AirIcuExtensionTest.mxml
Now that we built and packaged the native extension package AiricuExtension.ane, we are readu to use this and call ICU services in a test program.
The folder AirIcuExtensionTestsrc contains the test file AirIcuExtensionTest.mxml. The descriptor file AirIcuExtensionTest-app.xml has the details of native extension. Using the mxml compiler, AirIcuExtensionTest.swf is built as follows in AirIcuExtensionTest folder.
C:Flex4.5.1bincompc.exemxmlc +configname=air -external-library-path ..AirIcuExtensionbinAirIcuExtension.ane -output bin-debugAirIcuExtensionTest.swf — srcAirIcuExtensionTest.mxml
The output swf file AirIcuExtensionTest.swf is placed in the bin-debug folder.
1.5 Building AIR package for executing AirIcuExtensionTest
The final step is to package the above AirIcuExtensionTest .swf and AirIcuExtension.ane files into an AIR executable folder. Execute the following command
C:air3_beta2binadt -package -XnoAneValidate -storetype pkcs12 -storepass <passwd> –keystore <AIR certificate> -tsa none -target bundle AirIcuExtensionTest.air AirIcuExtensionTest-app.xml AirIcuExtensionTest.swf -extdir ….AirIcuExtensionbin
The output of the above command is a folder AirIcuExtensionTest.air. Inside the folder, there is AirIcuExtensionTest.exe. You can execute and see the output.
The sample illustrated how to invoke ICU from ActionScript. The AIR ICU extension is easy to build using the publicly available Adobe Flex SDK and AIR3 Beta 2 SDKs. It will be much easier to do all this in the future Adobe Flash Builder IDE using GUI. The advantages of this feature are
- AIR developers looking to develop international applications for desktop or mobile have the full power of ICU at hand. Many Unicode features, encoding conversions, IDN conversion utilities, string processing, transforms and many more international features can be easily coded.
- The native ICU extension once built can be used any any developer as it is a library.
- The Actionscript APIs calling ICU can be coded using the same signatures as ICU C++ API. This eliminates the learning curve.
- Since ICU is in native code, performance is not compromised.
- Since it is ICU, developers can expect cross-platform behavior in AIR programs.
- Since the extension is a AIR library, ICU updates can be easily re-packaged in to the ane file.
In the future once AIR3 is released, a full fledged ICU native extension with proper API definitions will be a great globalization project.