s中的Flex 4文本渲染:RichEditableText组件

时间:2011-03-01 18:02:00

标签: flex flex4

我很想知道是否有人可以了解Spark RichEditableText组件中的一些奇怪的文本呈现行为。

<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx"

creationComplete="handleApplicationCreationComplete()"
>
<fx:Script>
    <![CDATA[
        import flashx.textLayout.conversion.TextConverter;

        private static const DATA:Array =
        [
            "First sentence. This is a test of text rendering. How's it look?",
            "Let's see if this actually works correctly.",
            "Add some variety with the <b>bold</b> tag...",
            "Throw in a <a href='http://www.example.com'>link</a> as well!",
            "Well?! Does it work as expected? I think not..."
        ];

        private var currentIdx:int;

        protected function handleNextClick():void
        {
            currentIdx++;
            if(currentIdx >= DATA.length)
                currentIdx = 0;
            display(currentIdx);
        }

        protected function handleApplicationCreationComplete():void
        {
            currentIdx = 0;
            display(currentIdx);
        }

        private function display(idx:int):void
        {
            contentDisplay.textFlow = TextConverter.importToFlow(DATA[idx], TextConverter.TEXT_FIELD_HTML_FORMAT);
        }
    ]]>
</fx:Script>

<s:layout>
    <s:VerticalLayout />
</s:layout>

<s:VGroup width="100">
    <s:RichEditableText id="contentDisplay"
        width="100%"
        enabled="false" mouseEnabled="false"
        editable="false" focusEnabled="false"
    />
</s:VGroup>
<s:Button label="Next" click="handleNextClick()" />
</s:Application>

上述应用程序只需导航DATA数组中的五个句子(每次按下Next按钮)。无论出于何种原因,RichEditableText组件在设置新内容之前不会完全重置其视图(通过清除以前的文本)。从我可以收集到的,这个错误的渲染以某种方式基于行数和相对宽度的组合。我还发现如果我将width组件的RichEditableText属性设置为绝对值(比如100)而不是相对(百分比,100%)文本正确呈现。

据我所知,这种行为是无意的,实际上是一个错误。

Text on startup

Text after "next" is clicked

Text after "next" is clicked again

2 个答案:

答案 0 :(得分:0)

没有解决方案,这是框架中的一个错误......

答案 1 :(得分:0)

这是4.1 SDK中的错误。要解决此问题,您可以清除RTE,然后在子框架上更新它。

callLater(function workAround(richEditableText:RichEditableText, updateText:String):void
{
    richEditableText.text = updateText;
}
, [ myRichEditableTextComponent, myNewMessageText ]);

只需将此代码放在您之前更新RET的位置,然后传递组件和新文本。如果您使用文本流,只需用流替换文本和文本字符串,这应该是相同的。