One of the things I put a lot of work into for Spelling Plus Library was architecting it in a very modular, extendable fashion. The main reason for this was to allow developers to use it in the way that makes most sense for their projects. For example, Buzzword only uses the SpellingDictionary class, which handles all of the spell checking and spelling suggestion logic, and the WordListLoader, but manages the user interface themselves.
A secondary benefit is that many of the classes are very useful on their own. The best example of this is the TextHighlighter class that forms the core of the SPL SpellingHighlighter. It is a very powerful class for finding and highlighting words in a text field in real time.
It includes a ton of features, including support for manual selections, multi-line highlights, smart targeting, autoupdating on change and scroll, interactive highlights, and more. It will be gaining even more functionality in the upcoming 1.1 release of SPL.
Here is a simple demo of the TextHighlighter class in action. Less than 10 lines of code. It shows how you could use TextHighlighter to search for and highlight words in a text field. You can edit and scroll the text area, and the highlights will update in real time.
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '240',
'height', '390',
'src', '/blog/assets/TextHighlighterDemo',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'TextHighlighterDemo',
'bgcolor', '#686868',
'name', 'TextHighlighterDemo',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', '/blog/assets/TextHighlighterDemo',
'salign', ''
); //end AC code
}
This sample will be included with the 1.1 update of SPL.
I’ve considered licensing TextHighlighter separately from SPL, but I’m not sure if anyone would be interested. Let me know if you are.
Something like this (maybe not as feature packed though) was also made by Jack Doyle.
http://blog.greensock.com/category/text/
Looks good.
So simple, yet so useful. I love tools like these, good job!
One might also consider the Highlighter class in FlexLib, which is pretty darn good too. Just sayin’. 😉
http://flexlib.googlecode.com/svn/trunk/examples/Highlighter/Highlighter_Sample.swf
Tom – cool.Highlighter looks like a great class, though thankfully it doesn’t do everything I need for SPL (otherwise I’d feel silly for having reinvented the wheel). Guess it answers my question though, probably no need to license TextHighlighter separately. 🙂
Ha, just noticed they have a fire component too.
Very Cool Grant, can your library be manipulated to edit other things, like if I wanted to check code validation, like an AS Editor would? Is this possible with any features of SPL?
When you scroll the content, the highlight backgrounds update a bit late, a minor quirk tho! Love all your stuff, Flash has no limits!
Loving the speed of this! I never thought text processing would ever be so fast in Flash.
Now if only this (the spell checking part) was integrated in Snitter, it would save me and countless others from tweeting typo blunders.
Bo – this is because of invalidation, which lets it run more efficiently. We can eliminate the delay, but it increases the potential CPU usage because it may redraw more than once per frame.
Jerry – I’d need to know a bit more about what you’d like to do, but I can almost definitely say that portions of the code would be applicable, though it would likely require some extension.