在一系列字符上动态更改 Spark TextArea 文本颜色
希望获得一些 Flex 3/4 专家的帮助...
我正在尝试动态更改 Spark TextArea 控件中文本子集/部分的颜色。使用基于 MX 的 TextArea,我可以利用 mx.controls.textClasses.TextRange 类型并直接更改颜色,如下所示
: TextRange tr = new TextRange(theTextAreaControl, false, beginIndex, endIndex); tr.color = somePredefindColor;
TextRange 构造函数的输入参数:
- 第一个参数:将提供对底层 textField 属性的访问的 TextArea 控件
- 第二个参数:指示 TextRange 不会修改 TextArea 的内容
- 第三个参数:TextArea 文本中的起始索引位置string
- 第 4 个参数:TextArea 文本字符串中的结束索引位置
我该如何为基于 Spark 的 TextArea 控件执行此操作?我希望动态更改一系列文本的字体颜色,而不仅仅是整个 TextArea 并且我无法静态指定字体颜色。我在尝试重用 TextRange 类型时遇到的问题是,第一个参数预计提供 textField 属性,该属性当前不在基于 Spark 的 TextArea 控件上。我考虑过扩展基于 Spark 的 TextArea 控件来提供此访问器属性,但这似乎有点矫枉过正,并且可能不是最好的方法。
任何帮助将不胜感激。
谢谢, 迈克尔
Hoping to obtain the help of some Flex 3/4 gurus out there...
I am attempting to dynamically change the color of a subset/portion of text in a Spark TextArea control. Using the MX-based TextArea, I could leverage the mx.controls.textClasses.TextRange type and change the color directly as follows:
TextRange tr = new TextRange(theTextAreaControl, false, beginIndex, endIndex);
tr.color = somePredefindColor;
Input Parameters to TextRange constructor:
- 1st argument: The TextArea control that will provide access to the underlying textField property
- 2nd argument: Indicates the TextRange will not modify the content of the TextArea
- 3rd argument: The beginning index position in the TextArea text string
- 4th argument: The ending index position in the TextArea text string
How would I go about doing this for a Spark-based TextArea control? I am looking to dynamically change the font color for a range of text, not just the entire TextArea AND I cannot statically specify the font color. The problem I run into when trying to re-use the TextRange type is that the 1st argument is expected to provide the textField property, which is currently not on the Spark-based TextArea control. I thought about extending the Spark-based TextArea control to provide this accessor property but that seems like overkill and is probably not the best approach.
Any help would be greatly appreciated.
Thanks,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作 Spark 文本组件时,您需要使用文本布局框架 (TLF),它构建在 Flash Player 10 中引入的 Flash 文本引擎 (FTE) 之上。它使您能够主要控制文本的显示方式显示(代价是相当复杂。)这是一个很好的起点: 使用文本布局框架
When manipulating Spark text components, you'll want to use the Text Layout Framework (TLF), which is built on top of the Flash Text Engine (FTE) that was introduced in Flash Player 10. It gives you major control over how the text is displayed (at the cost of being pretty complex.) Here's a good place to start: Using Text Layout Framework