Update 2010-04-04: I’ve reviewed version 1.2 (see “ActionScript 2: Bugfixes in ‘ActionScript 2.0 Arabic Parsing v1.2′”).
Update 2010-03-26: The author has just released version 1.2 of the “ActionScript 2.0 Arabic Parsing” that includes my bug fixes and other improvements. You can find the new version here.
ActionScript 2 and the Flash Player up to version 9 does not support right-to-left languages like Arabic. Since ActionScript 2 internally uses UTF-8, the problem is not the handling of the characters, but the text engine that cannot properly render the texts. Just reading Arabic texts from a xml file and put it into a text field does result in the desired output: The characters are displayed in wrong order and the line breaks rules for Arabic language are not observed.
I’ve found a very interesting approach here (http://ixd-consultant.com/blog/2010/01/26/actionscript-2-0-arabic-parsing-v1-1/) that tries to solve the problem basically by analyzing the (Arabic) text character by character and uses Flash’s basic HTML support for text fields to align them to the right (arranged in the correct order). The library provides a static method StringUtils.parseArabic(input:String, tag:TextField, format:TextFormat):String that does all the magic stuff: It transforms a Arabic input string to a HTML formatted string that can be put into a text field.
Based on the author’s example I tried the algorithm with some Arabic texts and different font and text formats. The overall results looks quite good to me (I do not know anything about Arabian characters or grammar), but I needed to fix some bugs in the library:
- Fixed double line breaks for texts containing windows line breaks (\r\n) by adding (after the comment “// strip hard lines-breaks”)
input = input.split(“\r\n”).join(“\n”);
- Fix wrong line breaks by replacing
I do not analyzed the algorithm in detailed but I'm also confused about the following:
- The definition of latin characters does not include upper case characters.
var latinChars:String = "abcdefghijklmnopqrstuvwxyz1234567890>";
- Text fields with embedded fonts are handled different to those without embedded ones. Imho, with this differentiation the algorithm does not work properly for text fields without embedded fonts.