Flex中利用TextRange类高亮(hightlight)显示文本内容的例子
2009-11-11 16:34
791 查看
在显示搜索结果,标记重点文本内容等很多时候都需要用到文本高亮显示,接下来的例子演示了Flex中如何利用TextRange类,高亮(hightlight)显示文本内容。下面的Demo中用了两个Slider,拖动来选择高亮文本范围。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码
):
下面是完整代码(或点击这里察看): Download: main.mxml <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle" backgroundColor="white" viewSourceURL="srcview/index.html"> <mx:Script> <![CDATA[ import mx.events.SliderEvent; import mx.controls.textClasses.TextRange; private var tr:TextRange; private function slider_change(evt:SliderEvent):void { updateTextRange(); } private function textArea_change(evt:Event):void { // Recalculate length. slider.maximum = textArea.length; updateTextRange(); } private function updateTextRange():void { try { /* Default the TextArea control's text color back to black. */ tr = new TextRange(textArea); tr.color = "black"; tr.textDecoration = "normal"; /* Set the text color to red for the values in the Slider. */ tr = new TextRange(textArea, false, slider.values[0], slider.values[1]); tr.color = colorPicker.selectedColor; tr.textDecoration = "underline"; } catch (err:RangeError) { /* Somethin' ain't right! I dare say you have no text, son! */ } } ]]> </mx:Script> <mx:VBox width="380"> <mx:HBox> <mx:Label text="Text selection color:" /> <mx:ColorPicker id="colorPicker" selectedColor="red" /> </mx:HBox> <mx:HBox> <mx:Label text="Text selection range:" /> <mx:HSlider id="slider" thumbCount="2" liveDragging="true" snapInterval="1" dataTipPrecision="0" minimum="0" maximum="{textArea.length}" change="slider_change(event)" /> <mx:Label text="({slider.values.getItemAt(0)}, {slider.values.getItemAt(1)})" /> </mx:HBox> <mx:TextArea id="textArea" width="100%" height="120" change="textArea_change(event)"> <mx:text><![CDATA[The quick brown fox jumped over the lazy dog.]]></mx:text> </mx:TextArea> </mx:VBox> </mx:Application>
相关文章推荐
- Flex中如何利用focusIn和focusOut事件对表单中获得焦点的项目进行颜色高亮(highlight)显示的例子
- Flex中对文本实现高亮显示
- Flex中如何利用focusIn和focusOut事件,对表单中获得焦点的项目进行颜色高亮(highlight)显示。
- Flex中如何利用getTextField事件和numLines属性,计算出TextArea控件中内容的行数的例子
- Flex中如何利用getTextField事件和numLines属性,计算出TextArea控件中内容的行数的例子
- Flex中如何利用firstVisibleItem属性设置或取得第一个显示节点的例子
- Flex的TextArea控件中如何利用setSelection事件设定文本选中范围的例子
- 实现Flex的TextArea文本中关键字的高亮显示
- Flex中如何利用Camera.getCamera()和VideoDisplay#attachCamera()函数在VideoDisplay中显示用户摄像头内容
- Flex中如何设置或取消DateChooser控件当前日期高亮显示(highlighting)的例子
- 利用superfish显示到内容页并高亮显示菜单项
- 利用ToolTipManager类检测并取得Flex应用中当前ToolTip状态/内容的例子
- Flex中利用Repeater显示一组CheckBox控件的例子
- 利用js在浏览器中定位节点并且高亮显示节点间的内容
- Flex中如何利用useHandCursor和buttonMode属性在鼠标移到图片上显示手型光标的例子
- Flex中利用ToolTipManager类设定toolTip显示时间/停留时间的例子
- Flex中如何利用ToolTipManager类设定toolTip显示时间/停留时间的例子
- Flex中利用ExternalInterface API从JavaScript中获取内容并在Flex应用中使用的例子
- Flex中如何利用mx:HTTPService标签读取文本文件中的name/value这样的一对数据并显示在DataGrid中的例子
- Flex中利用Repeater显示一组RadioButton控件的例子