AS3 TextHighlighter
June 22nd, 2009 • ActionScript, Flash
Because of the lack of text highlighting capabilities for Flash TextFields I coded a small class with a simple API to highlight text with your custom style. For your own styles you just have to implement an interface. The highlight method takes either a String or Regular Expression as argument.
The class doesn’t work for scrolling text at the moment, but feel free to extend the class.
example:
code:
// highlight container var highlight : Sprite = new Sprite(); addChild(highlight); // create textfield var textField : TextField = new TextField(); addChild(textField); // apply text style and add text ... // highlight style var style : IHighlightStyle = new SimpleHighlightStyle(0x00ff00, 0.5); // highlighter var textHighlighter : TextHighlighter = new TextHighlighter(textField, highlight, style); textHighlighter.highlight(/far/gi); textHighlighter.highlight("Duden", false);
files:
version 0.1
TextHighlighter_01.zip
16 Responses (Add Your Comment)
-
-
Mark Holgerson October 11, 2009at 6:53 am
This is great. Thank you for writing this class.
I am running into problems however with special html characters. Is there a way to highlight special characters such ampersands or dollar signs?
-
ariisom November 11, 2009at 3:07 pm
is there a way to highlight dynamically? It’s like when you highlight a text for copy pasting…can be any words from the text. So the textHighlighter.highlight(…); would receive the text from mouse coordonates.
-
Hi,
It’s great and all but can I highlight so that lets say after the word “layer” is highlighted and before the word “layer1″ is highlighted? -
Thx that helps a lot! :D
next question: how can I create a multi line highlight so how can I highlight something like:hello bla bla bla
lol XD
hehe no das verstehe ich nicht?
-
THX :D
-
A feature packed version of this kind of text highlighter tool is available here: http://activeden.net/item/text-highlighter-basic-tool/121574?ref=boee
-
Thanks, Martin! This is exactly what I was looking for.
Nice. Thanks for sharing this :)