在闪存中加载RTL(从右到左语言文本)XML(AS3)

时间:2012-08-31 18:16:15

标签: actionscript-3 flash right-to-left

我是flash的新手,想要在flash as3和Flash player 10中加载xml文件。 我不想用TLF! (TextLayoutFramework)因为它在编译时会抛出错误 当我以utf-8编码加载XML时,单词从左到右而不是从右到左排序 - 每个单词都写在最后一个单词之前而不是之后。

任何想法如何解决?

这是我的XML加载程序代码:

var css_file:String = "gstyle.css";
var fa_item_list = new Array();
var fa_item_group:MovieClip = new MovieClip();
var item_width:Number = fa_mask.width;
var item_height:Number = 0;
var item_spacing:Number = 15;
var item_padding:Number = 0;
var i:Number;
var total:Number;

var fa_xml:XML = new XML();
var fa_style:StyleSheet = new StyleSheet();
var css_loader:URLLoader = new URLLoader();

function push_array(e:Event):void 
{
    fa_xml = XML(e.target.data);
    total = fa_xml.item.length();
    for( i = 0; i < total; i++ )
    {
        fa_item_list.push( { content: fa_xml.item[i].content.toString() } );
    }
    load_css();
}

function load_xml(xml_file:String):void
{
    var xml_loader:URLLoader = new URLLoader();
    xml_loader.load( new URLRequest( xml_file ) );
    xml_loader.addEventListener(Event.COMPLETE, push_array);
}

function load_css():void
{
    css_loader.load( new URLRequest(css_file) );
    css_loader.addEventListener(Event.COMPLETE, css_complete);
}

function css_complete(e:Event):void 
{
    var css_format:TextFormat = new TextFormat();
    fa_style.parseCSS(css_loader.data);
    create_item_list();
}

function create_item_list():void
{
    for( i = 0; i < total; i++ )
    {
        var fa_item = new MovieClip();
        fa_item.addChild( create_item_desc( fa_item_list[i].content ) );
        fa_item.addChildAt( create_item_bg( fa_item.height, i ), 0 );
        fa_item.y = item_height;
        item_height += fa_item.height + item_spacing;
        fa_item_group.addChild( fa_item );
    }

    this.addChild( fa_item_group );
    fa_item_group.mask = fa_mask; 
    fa_sb.scrolling("fa_item_group", "fa_mask", 0.50);  // ScrollBar Added
}

function create_item_bg( h:Number, item_no:Number )
{
    var fm_rect:Shape = new Shape();
    fm_rect.graphics.beginFill(0xDED9D1, 0);    // ITEM BACKGROUND COLOR
    fm_rect.graphics.drawRoundRect(0, 0, item_width, h + item_padding * 2, 0);
    fm_rect.graphics.endFill();
    return fm_rect;
}

function create_item_desc( item_desc:String )
{
    var fm_text = new TextField();
    fm_text.x = item_padding;
    fm_text.y = item_padding;
    fm_text.width = item_width - item_padding * 2;
    fm_text.styleSheet = fa_style;
    fm_text.htmlText = item_desc;
    fm_text.multiline = true;
    fm_text.wordWrap = true;
    fm_text.selectable = false;
    fm_text.autoSize = TextFieldAutoSize.LEFT;
    return fm_text;
}

1 个答案:

答案 0 :(得分:1)

只有TLF文本字段才能正确处理从右到左的文本。

import fl.text.TLFTextField;
import flashx.textLayout.formats.Direction;

var tlf:TLFTextField = new TLFTextField();
    tlf.direction = Direction.RTL;

如果您想使用TextField对象,此库可以为您提供帮助(非免费):http://www.arabicode.com/flarabyas3/main