我有一个文本,其中有非常长的要突出显示的单词列表,为每个单词调用setTextFormat()需要花费很长时间。有什么方法可以加速这个操作吗?我尝试过在DisplayObject的列表中使用未实例化的TextField,以绕过呈现阶段,但我发现性能是相同的。有什么想法吗?
发布于 2010-01-18 22:20:27
我强烈建议你看看Text Layout Framework处理富文本样式的新模式。
本质上,TLF有一个TextFlow对象,其中包含文本的模型,包括所有相关的跨度特定格式。这与文本显示的“视图”部分不同,后者将由单独的flow composer和EditManager管理(在可编辑文本的情况下)。
因此,您可以在文本模型的较大范围内执行格式转换,并且仅在最后根据命令重新绘制视图本身。
发布于 2010-12-16 09:17:50
使用TLF,在开始给所有东西着色之前,调用beginCompositeOperation();最后调用_objEditManager.endCompositeOperation();下面是我的代码中的一个示例
_objFlow.interactionManager = _objEditManager;
_objEditManager.beginCompositeOperation();
DocColoringUtils.SetRegionColor(_objFlow, iStart, iEnd, BackgroundColor.TRANSPARENT, 1);
var colRegions:Vector.<Region> = _objResourceMediator.GetCurrentResourceRegions();
var objEditingExcerpt:Excerpt = _objExcerptingMediator.EditingExcerpt;
if (_objExcerptingMediator.InEditMode == true && objEditingExcerpt != null)
{
DocColoringUtils.ColorizeForEditMode(_objFlow, iStart, iEnd, colRegions, objEditingExcerpt.StartIndex, objEditingExcerpt.EndIndex, _objExcerptingMediator.SearchMatchRegions);
}
else
{
DocColoringUtils.ColorizeForNonEditMode(_objFlow, iStart, iEnd, colRegions, _objExcerptingMediator.SearchMatchRegions);
}
_objEditManager.endCompositeOperation();
_objFlow.interactionManager = _objSelectionManager;最后,您应该只对可见范围+/- 300个字符的内容进行着色。然后在滚动时对当前可见区域重新着色。这适用于http://www.Dedoose.com上的一些超大的文档。
发布于 2010-01-18 02:01:44
如果它是一个htmlText,并且你想要突出显示的单词被放在像<strong>这样的标记中,你应该查看StyleSheet对象,你可以通过loading a css file来定义它的样式,或者你可以像这样分配样式:
var style:StyleSheet = new StyleSheet();
var strong:Object = new Object();
strong.textDecoration = "underline";
style.setStyle("strong", strong);https://stackoverflow.com/questions/2081923
复制相似问题