代码之家  ›  专栏  ›  技术社区  ›  Frank

Flex SDK:如何使用TextLayoutFramework将选项卡分配给Spark RichtText

  •  0
  • Frank  · 技术社区  · 9 年前

    我正在尝试使用TextLayoutFramework来使用选项卡。根据一些例子,这应该是可行的,但不能。。。

    你知道为什么txt用空格而不是换行符或制表符显示如下吗?

    111111 222222 33333 44444 55555 66666 77777
    

    这是使用的代码:

    <fx:Script>
        <![CDATA[
            import flash.text.engine.TabAlignment;
    
            import flashx.textLayout.conversion.TextConverter;
            import flashx.textLayout.formats.TabStopFormat;
            import flashx.textLayout.formats.TextLayoutFormat;
    
            private function setText() : void
            {
                // Test content
                var txt : String = "<p><span>111111\n222222\t33333\t44444\t55555\n66666\t77777</span></p>";
                var xml : XML = new XML("<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" + txt + "</TextFlow>");
    
                // Define three tab positions
                var tabStop1:TabStopFormat = new TabStopFormat();
                tabStop1.alignment = TabAlignment.START;
                tabStop1.position = 50;
    
                var tabStop2:TabStopFormat = new TabStopFormat();
                tabStop2.alignment = TabAlignment.CENTER;
                tabStop2.position = 150;
    
                var tabStop3:TabStopFormat = new TabStopFormat();
                tabStop3.alignment = TabAlignment.END;
                tabStop3.position = 250;
    
                // Define the formatter
                var format:TextLayoutFormat = new TextLayoutFormat();
                format.tabStops = new Array(tabStop1, tabStop2, tabStop3);
    
                // Put the text in the textbox
                txtBox.textFlow = TextConverter.importToFlow(xml, TextConverter.TEXT_LAYOUT_FORMAT);
    
                // Assign the formatter to the textbox
                txtBox.textFlow.format = format;
            }
        ]]>
    </fx:Script>
    
    <s:RichText id="txtBox" top="25" left="25" width="400" height="200" />
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Frank    9 年前

    在ApacheFlex用户组的帮助下,这是实现这一目标的最简单方法,只需更少的代码!!!

    var txt : String = "11111\n222222222222222\t333\t44444444\t555555\n66666\t77777777\t88\t99999\naaaa\tbbbbbbbb\tcccccccc\tddd";
    txtBox.text = txt; 
    txtBox.setStyle("tabStops", "e200 c250 s300"); 
    
    <s:RichText id="txtBox" top="25" left="25" width="600" height="200" />
    

    请参见: http://apache-flex-users.2333346.n4.nabble.com/How-to-assign-tabs-to-a-Spark-RichtText-with-TextLayoutFramework-td11883.html