November 22, 2003
Right-to-Left in Flash: A New Attempt

Ram Almog asked me to publish his solution for circumventing the inability of Flash to render right-to-left texts correctly. Of course I do. Here's his comments: "Its far from perfect but maybe someone with an in-depth knowledge in bi-di algorithms can help to finalize it. Currently, this solution supports any right to left text. No need to flip the original text you wrote in any Unicode text editor (like notepad or XMLnotepad). Punctuation works great and in most cases I am able to work my way and put html tags into it. The solution does not support putting English and Hebrew texts together in the same line and words combined with numbers (numbers alone would work fine)."

Well, see yourself or download the fla.

Posted at November 22, 2003 08:29 PM | Further reading
Comments

Hey Mario :)

Ram contacted me a few weeks ago about his solution and I posted it on my blog as well. Thanks for doing the same and supporting our attempts to use dynamic Hebrew in Flash :)

Cheers,

Amir

Posted by: Amir Dotan on November 23, 2003 12:18 AM

Doesn't work for me (on linux).
I just see a white rectangle.

Posted by: Dood on November 23, 2003 02:49 AM

ditto for win2k. flash version thing?

Posted by: PaulH on November 23, 2003 03:18 AM

Hi all,
Mario did not put the xml file in the same directory as the swf. you can download both at my site (www.ralmog.com)
Ramster

Posted by: ram on November 23, 2003 09:32 AM

Oops - I've uploaded the XML file now. Sorry Ram!

Posted by: Mario Klingemann on November 23, 2003 10:51 AM

Ram - I don't read Hebrew so I don't know if what I'm seeing is displaying correctly - any chance of posting a screengrab?

I guess you had the same problem with numbers which I experienced earlier this year -I wrote a couple of functions to reverse Hebrew text, while preserving numbers:

String.prototype.reverseSpecial = function() {
// ------ Parse text into numeric & string chunks
var chunks = [];
var mode = "";
var lenMax = this.length;
for (var len = 0; len<lenMax; len++) {
if (this.charAt(len)+1 && this.charAt(len) != " ") {
// This character is numeric
if (mode != "num") {
mode = "num";
chunks[chunks.length] = this.charAt(len);
// Start new numeric chunk
} else {
chunks[chunks.length-1] += this.charAt(len);
// Add to current numeric chunk
}
} else {
if (mode != "str") {
mode = "str";
chunks[chunks.length] = this.charAt(len);// Start new text chunk
} else {
chunks[chunks.length-1] += this.charAt(len);// Add to existing text chunk
}
}
}
// ------ Create output : reverse all non-numeric chunks
var outString;
for (var arr in chunks) {
if (String(Number(chunks[arr])) != "NaN") {
} else {
chunks[arr] = chunks[arr].reverseString();
}
outString += chunks[arr];
}
return outString;
};
String.prototype.reverseString = function() {
var out;
var len = this.length;
while (len--) {
out += this.charAt(len);
}
return out;
};

trace("This is a test sentence 1234 this is a test sentence 3.141592".reverseSpecial());
// 3.141592 ecnetnes tset a si siht 1234 ecnetnes tset a si sihT

Luckily I was only using single lines of text, so I didn't need to address the problem of line breaks.

dAN

Posted by: dAN on November 24, 2003 12:15 PM

Hi dAN
Actualy, the benefit of my solution is that you do not have to reverse the order of the letters as I am using unicode text. Apparantly, unicode letters holds the direction of the letter in the double byte char code. that means that the flash text renderer knows that it should render the text from right to left. Numbers as for themselves are not a problem. they are rendered left to right. The only irritating thing is when they appear at a warp point. Warping is done Left to right (this is why I needed to add the "Left to Right Embed" character after punctuation marks. In decent HTML browsers you can force the text renderer to render a certain text completly from right to left (using the direction tag dir=rtl). Unfortunatly, this is not the case with the flash renderer.
As for your questions, most odds is that you see the text ok. If you want a screen grab, just send me an email and I'll send one. :)
Ramster

Posted by: Ramster on November 25, 2003 11:01 PM

Hi
Does anyone know that macromedia will support RTL in Flash Player or not?
Does the-right-to-flash.com has any impact on macromedia or not?
When would we be able to use Flash for our applications? :(

Posted by: Behrang on November 29, 2003 07:44 PM

Has anyone tackled input text fields? Do any of them work?

Posted by: David Wallach on February 12, 2004 05:31 PM

Hi!

Maybe someone here has a solution:
I am loading hebrew text from an XML, all works fine. All fonts are embedded (I used the flip-trick).
But for some reason, on some machines the hebrew text just does not display!!!
The only text I see - are the numbers and special characters!
Does anyone know why this is? Does this have to do with the encoding of the XML?

Please help!!

Posted by: bat7 on November 14, 2004 09:30 AM

Hi!

Maybe someone here has a solution:
I am loading hebrew text from an XML, all works fine. All fonts are embedded (I used the flip-trick).
But for some reason, on some machines the hebrew text just does not display!!!
The only text I see - are the numbers and special characters!
Does anyone know why this is? Does this have to do with the encoding of the XML?

Please help!!

Posted by: bat7 on November 14, 2004 09:31 AM

If this only happens on some machines it probably means that you did not embed the fonts. In that case those machines might not have the necessary Hebrew fonts installed.

Posted by: Mario Klingemann on November 14, 2004 10:59 AM

It has to do with the encoding of the XML. Flash only works well with utf-8 and utf-16 encoding, it seems... I also heard you can leave out the whole XML declaration, but that also does not always seem to work!! Anyone with experience with this??
Thank you!

Posted by: bat7 on December 5, 2004 02:55 PM

I am currently working on a project where I need to support Arabic text in Flash, further complicated by the fact that I'm a US developer who doesn't speak Arabic! :-)

I've used the solution posted by Ram Almog posted here, it seems to work great, the only problem I have left is the line break issue.

I was wondering if anyone had been able to overcome the line break issue? I've been scratching my head over it for a while and could sure use some help if somebody else has already solved it! :-)

Anyone? :-)

Posted by: TJ on January 12, 2005 11:26 PM

Hey Ram, Mario

Guys, we have been searching for some solution for displaying arabic text on flash player now for ages. we got your link from Macromedia folks and it was amazing to see what was displayed, although it didnt make much sense coz i dont understand arabic.
we are working on a huge project which can go ahead using Flex only if we can handle arabic text. can you send in few details to me on sriduvvuri@yahoo.com
it would be really useful. i did find some ray of hope reading the posting of TJ that he could successfully get arabic text on flash. so some tips from you guys on what and how to do would be really useful

Cheers

Posted by: Srikanth on February 7, 2005 06:30 AM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?



Thank you!

Most Visited Entries
Sketches, Works & Source Code
Lectures
Contact
Backlog
In Love with
Powered by
Movable Type 2.661

© Copyright Mario Klingemann

Syndicate this site:
RSS 1.0 - RSS 2.0

Quasimondo @ flickr
Quasimondo @ LinkedIn
Quasimondo @ Twitter
Quasimondo @ Facebook
Quasimondo @ MySpace
Quasimondo is a Bright
Citizen of the TRansnational Republic
My other blog in german
Impressum


My family name is written Klingemann,
not Klingelmann, Klingeman, Klingaman, Kingemann,
Kindermann, Killingaman, Klingman, Klingmann, Klingonman
Klingemman, Cleangerman, Klingerman or Kleangerman

profile for Quasimondo at Stack Overflow, Q&A for professional and enthusiast programmers