1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.64 out of 5)

Update: a newer version available here

Well, this issue is a very old one, I’ve always experienced annoying problems each time I try to render Arabic text on run-time using Flash and ActionScript 2.0, Flash doesn’t support right-to-left languages, and when it comes to Arabic, we are talking about proper characters joining and word wrapping ..

I never stopped tracking this specific issue, googling it to find any new solution has been developed somewhere, for a long time I can only find this one, the guy have it perfectly solved, he was having his solution implemented using ActionScript 2.0 at some point earlier, but he stopped publishing that and kept his latest version only, which works with ActionScript 3.0, and for old fashion guys like me he left another version to manually copy proper Arabic text using an AIR application he developed here

Recently, Adobe says that they finally supports right-to-left languages along with bi-directional and complex script ones, only using ActionScript 3.0 and it requires Flash Player 10 or above, they even have an open source framework called Text Layout Framework, it’s perfect actually, it should put an end to this issue, but ..

I have my own objections, I made my quick test to check their new technique here, Arabic text is finally rendered properly, but why we have to add so many childs to our display list from different TextLines and TextBlocks instead of a single TextField? also we have to set a max width, and I couldn’t find a way to scroll through text unless I used a custom scroller and masking the text just like any other MovieClip or DisplayObject, personally, I find this much complicated experience just to display simple string!

I do like ActionScript 2.0 a lot more anyway, not just for handling text easily, but for many other reasons, I can stop to post another article to explain why I’m saying this, right now we need to know what I’ve reached regarding to our issue ..

In a nutshell, ActionScript 2.0 used to refuse right-to-left languages, so we can’t embed fonts, wrap text properly, and when it comes to Arabic text we also see our characters splitted which is inappropriate for Arabic readers, the old solution for this was loading text encoded in UTF-8 from external text/xml files, and still no word wrapping, and on Mac machines Arabic letters still splitted, we can align text but its direction still not right-to-left ..

So, logically, I know that I have to construct my Arabic text manually, to achieve that I had to analyze Arabic rules for character joining with all it’s special cases, and then find a way to force its direction to be left-to-right, and the word wrapping part is not that hard after all, this is basically what I did actually!

My only problem was in finding a way to inject all proper Arabic characters with its unique cases, for a long time I found that very difficult, Flash doesn’t allow me to copy those from other text processing tools, and of course there’s no way to type each character a lone in different cases using keyboard ..

Finally, I found a way to do that, and it was extremely simple! I found these charts at unicode official website, and that’s it! now I can instruct ActionScript 2.0 to handle my Arabic characters properly!

You’re most welcome to use and test my parseArabic method, it supports word wrapping, right-to-left, bi-directional (inline English characters), embedded fonts and custom text formats, here is an example:


download the above example here

The above approach doesn’t support html tags yet, it’s a bit confusing, but as I said, you’re welcome to contribute, your reviews can help improving the code ..
This may help any ActionScript 2.0 loyal friend, and I think the same approach can be used for ActionScript 3.0 as well, I will post that soon ..




Social Comments

30 Advanced Comments

Martin
January 6th, 2010

Thanks for this post! It´s been really useful, since I´ve been struggling for a solution to this ptoblem for several days. The parseArabic method worked fine for me.

kaled
January 13th, 2010

kindly explain how o use it with dynamic text in flash if I’m loading an external Arabic text file.

I’m new in action script and i need it for Arabic applications

regards

Bahaa
January 14th, 2010

Hello my friend, I would like to thank you for your trying to help us…

but.. I’m really have no knowledge about actionscripts or nothing about it… I’m even beginner in Flash, I installed the Adobe Flash CS4 professional, and I found that I can’t write Arabic, Noway.. and word splitted into each lonely character .. and from left to right

Now at the end of your topic, I downloaded the file “parsearabic_v1.0.zip”

but I don’t know where should I put it, or where should I extracvt the included files in?

or should I learn some programming languages to use it?? I hope not.

So please help me and tell me how could I use your file or where should I put it at???

Thank you very much, waitting for your answer… thanks



January 17th, 2010

@kaled

you can follow this example



January 17th, 2010

@ Bahaa

you’re most welcome

parseArabic method works only with programmatically rendered Arabic text, that means using ActionScript 2.0, if you don’t like to learn that, then I suggest that you simply use this example, paste your arabic text into the input field, then copy the correct arabic from the output field to your static TextField

January 17th, 2010

Hi,

Very good work, I did notice some flaws however in the coding, here’s an example:

Try to use the follwing in the text:
???? ?? ????? ?????? ???????? ??????????? ???????? ???????? ???????? ????????? ???????? ???????? ?????? ??? ???? ??????? ???? ???? ??? ????? ??? ????? ???????????

and you will see that the ligatures break when certain diacritics are used…

January 17th, 2010

it seems that arabic text was not rendered correctly in the comment as well, here’s a link to a screenshot:

http://www.sidani.info/test/screeny.jpg

Martin
January 18th, 2010

As I mentioned – the method worked fine for me.. but now I found that the arabic text gets rendered with line break problems in Mac. Did you experience this problem as well? Is there a solution to it? Thanks

January 19th, 2010

Great Job Ahmad.
I suppose this could help with the basic text display components.

Though you can’t really feal comfortable selecting the text.

Anyway I am working on a hack for solving the flow direction issue. Which will allow dynamic text input fields in runtime as well.

I will keep you posted.

January 19th, 2010

Dear Sir
Excellent work.
However for some combination of Arabic still there is some problem.
Do you have any latest updates??
Please kindly help me.
Dominic
Riyadh
Saudi Arabia

mohamed
January 22nd, 2010

Thanks for this post! It´s been really useful but I can’t use it to load text from xml file I face the same problem could anyone put an example for loading text from xml file by using this solution.

thanks my friends.



January 26th, 2010

@ Basem

Thank you very much, this is very encouraging, here is a newer version with more detailed specifications with a few improvements ..

@ Wassim, Martin, Dominic

Thank you all for your reviews, there’s a newer version available here, I hope your issues has been covered properly.

@ Mohamed

there’s an example using external XML included at the top of the class, and you’re welcome to use this one ..

February 2nd, 2010

I’ve been looking for this tutorial, thank you so much.



February 2nd, 2010

you’re most welcome :)
there’s an improved version available here as well

Waseem
March 19th, 2010

Slam Alaycom
I want to make like this.
But this is the result
===================================

If you have a new update to solve this problem.
I owe you.
Please>>>
Help me

Waseem
March 19th, 2010

Sorry
This is the result

http://yfrog.com/cc98996728j

Waseem
March 23rd, 2010

pleas . . .
If you don’t mind, I have another Question.
I want to load picture into a movie clip using (loadMovie)function
But the trasformation point of pictures are normally in the up left.
I want to make it in the middel
How can I do that Please > >



March 26th, 2010

I have newer version of this method available here, you’re welcome to review and comment on this one instead ..

About your image loading origin point, you can use the following code instead:

var lodr:MovieClipLoader = new MovieClipLoader();
var lsnr:Object = new Object();
lsnr.onLoadInit = function(target:MovieClip) {
	target._x -= target._width/2;
	target._y -= target._height/2;
}
lodr.addListener(lsnr);
lodr.loadClip("myphoto.jpg", photo);
Waseem
March 26th, 2010

thanks alot ixdc
But I have made that before,
the photo still rotate from the top-left piont.
Could you make a zip file contain (photo – fla – swf ) in AS2
I want to rotate the loaded photo form the center not form the top-left.
Please :(



March 26th, 2010

Just bury the code I sent you into another MovieClip (as parent), then you rotate the parent movie, here is a working example ..

Waseem
March 27th, 2010

It works perfectly
I ask God to bless you,

Waseem
March 29th, 2010

The latest Question Please . .
I have a project Consists of 2 DVDs with an Only one intro.
When the user presses button in this intro I want make sure if this DVD is No.1 or No.2
Something like this,
if (DVD ==No.1) {
fscommand (“exec” , “setup.exe”);
} else { trace (“Please insert DVD No.1″);
}
Alot thanks for you. :)

Waseem
April 1st, 2010

OH NO ! !
I was made this page in favorite, So I open it every day.
waiting for your answer > > >
Please ):



April 2nd, 2010

I remember that you can not detect drive label or its local path from Flash, but I think you can do a work-around to detect which DVD disc is currently in, by reading another simple plain text file on the disc (i.e. a file named “disc” with no extension, but still a text file), click here for an example ..

Waseem
April 2nd, 2010

1000000 thanks for you *_^
Could I ask you later if I need help?



April 2nd, 2010

Sure, and you don’t need to post your questions as comments on this post unless they’re related to the Arabic Parsing method ..
Just drop me an email whenever you like, I’d be glad to help ..

Avi
May 4th, 2010

I still see the bug as it doesn’t render the “TANWEEN”. Can you take a look of this issue.

AlaTounsi
January 1st, 2011

Thank you so much for sharing your code and for your solution to this annoying problem in Flex/Air/Flash

Unfortunately I couldn’t use your StringUtils class cause it’s extending String Class
This is impossible since String is a final class in ActionScript 2.0 and you should have a compilation error saying “base class is final””

So my question: How did it work for you?



January 5th, 2011

@AlaTounsi

Just remove that part ( extends String), it’s no use anyway, I should’ve removed that long ago ..
Thanks for the tip ;)

April 23rd, 2011

thank you so so so much you’r a flash angel