9

How can I display arabic text from right to left with as3?

STF
  • 1,485
  • 3
  • 19
  • 36
gabitzish
  • 9,535
  • 7
  • 44
  • 65

7 Answers7

9

This code will do the trick:

import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.external.*
import fl.text.TLFTextField;
import flash.text.TextFormat;

import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;


var arabicTextField:TLFTextField = new TLFTextField();
arabicTextField.antiAliasType = AntiAliasType.ADVANCED;
arabicTextField.mouseEnabled = false;
arabicTextField.selectable = false;

arabicTextField.direction = flashx.textLayout.formats.Direction.RTL;

var fmt:TextFormat = new TextFormat();
fmt.color = 0xFFFFFF;
fmt.font = "arialArabic"
arabicTextField.embedFonts = false;
arabicTextField.defaultTextFormat = fmt;
arabicTextField.setTextFormat(fmt);
Ellen S
  • 1,047
  • 1
  • 13
  • 18
2

I know this is an old thread. But still the most useful snippet around for RTL Text. Thanks Ellen.

Let me add some experiences in coding for iOS on Flash Builder 4.7 in times of CC:

Flash Builder doesn't ship with the TLFTextField and its supporting classes needed to display Arabic and other RTL languages on iOS.

Between CS6 and CC Adobe has even dropped those classes from Flash Professional. Probably because the standard TextField class has been improved.

Still, on iOS RTL and and Arabic Ligatures will not work out of the Box. If you use the TextField class AirSimulator of FlashBuilder will display correctly. Not if you run the same code on iOS.

StageText and its NativeText wrapper will render correctly but do have disadvantages for static text.

You might think of reintroducing TLFTextField. Here's how you can do it:

  • Install Flash Professional CS6 (!) from the Creative Cloud
  • In the "libs" subfolder of the programfolder you'll find two SWCs that contain the classes needed to use TLFTextField: TLFRuntime.swc & textLayout.swc
  • Copy the SWC in your ProjectFolder and include it in Flash Builder by opening your project's properties -> ActionScript Build Path -> Library Path -> Add SWC (or Add SWC-Folder)

This should make Ellen's code work on FlashBuilder 4.7 for iOS with Air SDK 3.9

You could probably expect the standard TextField display Arabic and other RTL languages correctly in future releases of Air.

Al Coda
  • 56
  • 3
2

The Text Layout Framework can handle right to left text.

maxmc
  • 4,218
  • 1
  • 25
  • 21
1

try to add textformat with propriety right alignment

var txtFormat:TextFormat = new TextFormat();
txtFormat.align = "right";
Yosra Nagati
  • 780
  • 2
  • 8
  • 26
1

Additionally, you probably will need to include the fonts you use in your library

vvMINOvv
  • 1,768
  • 4
  • 22
  • 45
0

If you're not opposed to the flex framework, it now includes a decent internationalization library that should allow you to do this easily. Here's a decent place to get started http://devgirl.org/2011/03/15/flex-4-localization/

Robert Smith
  • 385
  • 4
  • 15
0

I've also had success with FlarabySWF - it costs some money (not alot) but it actually works quite well in my experience.

sapptime
  • 430
  • 3
  • 9
  • Loving the Flaraby license conditions... "As a buyer of FlarabySWF, you can use it under condition that the text you want to convert AND the converted text do NOT contain or insinuates in any way to anything that violates Islamic Sharia or to be against Islam itself, including but not limited to: any works that contradicts with Islamic Ethics like sex or pornography, Gambling, anything that is against Religions or Messengers/Prophets". – chichilatte Jun 01 '15 at 16:29