我有一个搜索和结果页面,我想在结果文本中突出显示搜索过的关键字。有人建议我为此使用 TextLine,但我无法弄清楚如何使其工作。我开始了一个简单的、可编译的虚拟应用程序,希望有人能给我一些关于如何继续的提示:
<?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"
initialize="initApp();">
<fx:Script>
import flash.display.Sprite;
import flash.text.engine.*;
private var textLine:TextLine;
private function initApp():void {
var normalFormat:ElementFormat = new ElementFormat(null, 12, 0x000000);
var highlightFormat:ElementFormat = new ElementFormat(null, 14, 0xff0000);
var textBlock:TextBlock = new TextBlock(new TextElement("This is text that has KEYWORDS. I would like to highlight these KEYWORDS by changing their font color and adding a light yellow background graphic.", normalFormat));
textLine = textBlock.createTextLine();
textLine.y = 100;
embeddedFontHolder.addChild(textLine);
}
</fx:Script>
<mx:UIComponent width="100%" id="embeddedFontHolder" />
</s:Application>
有人有想法么?
干杯,巴兹