开发者

Arabic text in as3

开发者 https://www.devze.com 2023-02-03 07:00 出处:网络
How can I display arabic text from right t开发者_高级运维o left with as3?This code will do the trick:

How can I display arabic text from right t开发者_高级运维o left with as3?


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);


The Text Layout Framework can handle right to left text.


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.


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


try to add textformat with propriety right alignment

var txtFormat:TextFormat = new TextFormat();
txtFormat.align = "right";


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


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消