Language Version : | ActionScript 3.0 |
Runtime Versions : | AIR 1.0, Flash Player 10 |
A comprehensive convenience class that bundles a context menu UI,
the spelling engine, the dictionary loader, and user dictionary support
to enable a single-line integration of spell checking functionality into
any custom UI component built around TLF TextFlow.
For advanced text editing applications, more complex features are likely required.
For those applications, we recommend bypassing this class and utilizing the SpellChecker
class directly.
In order to display Squiggly custom right-click context menu, SpellUIForTLF extends TLF
ContainerController
class and overrides createContextMenu() method
of
ContainerController
. This could have the following side-effects for a Squiggly client:
- In case the Squiggly client application uses a derived controller that inherits from ContainerController class in order to show custom context menu items, Squiggly
context menu will override that. That essentially means that after SpellUIForTLF.enableSpelling() is called, client's own custom right-click menu items, if any, will not be
accessible.
- Incase any ContainerController api needs to be called after SpellUIForTLF.enableSpelling() has been called, the client application will need to get the controller objects afresh
from the TextFlow's FlowComposer. This is needed since SpellUIForTLF replaces ContainerController objects with new SquigglyCustomContainerController(derived from ContainerController) objects.
SpellUIForTLF
uses the SpellingConfig.xml file to lookup corresponding resource files for a given locale.
The default location of SpellingConfig.xml is [yourapplicationDirectory]/SpellingConfig.xml. This could be customized using
spellingConfigUrl
property of SpellUI
. You don't have to change the content of this file. However,
if you want to add a new language, to use an alternative dictionary or to customize the location for your dictionaries, you can modify it.
There's an known issue with IIS web server when loading dictionary files with unknown extensions, in which case you can modify the XML to work around it.
A sample SpellingConfig.xml will look as follows:
<?xml version="1.0" encoding='UTF-8'?>
<SpellingConfig>
<LanguageResource language="English" languageCode="en_US" ruleFile="dictionaries/en_US/en_US.aff" dictionaryFile="dictionaries/en_US/en_US.dic"/>
<LanguageResource language="Spanish" languageCode="es_ES" ruleFile="dictionaries/es_ES/es_ES.aff" dictionaryFile="dictionaries/es_ES/es_ES.dic"/>
<LanguageResource language="Portuguese" languageCode="pt_PT" ruleFile="dictionaries/pt_PT/pt_PT.aff" dictionaryFile="dictionaries/pt_PT/pt_PT.dic"/>
<LanguageResource language="Italian" languageCode="it_IT" ruleFile="dictionaries/it_IT/it_IT.aff" dictionaryFile="dictionaries/it_IT/it_IT.dic"/>
</SpellingConfig>
Note: The languageCode can be an arbitrary value, as long as you are consistent when passing them to the Squiggly classes.
However, we highly encourage you to follow the two part Unicode language identifier format.
For more information, please consult the latest Unicode Technical Standard that can be found at: http://unicode.org/reports/tr35/.
spellingConfigUrl:String
The URL for the spelling config xml file. If you haven't specify it, the default URL is [applicationDirectory]/SpellingConfig.xml. Note that we don't validate the URL, if the file doesn't exist, you will get an error when calling enableSpelling() function.
Implementation public static function get spellingConfigUrl():String
public static function set spellingConfigUrl(value:String):void
Example The following code customize the spellingConfigUrl before enabling spell checking.
SpellUIForTLF.spellingConfigUrl = "./config/MySpellingConfig.xml";
SpellUIForTLF.enableSpelling(textFlow, "en_US");
public static function disableSpelling(comp:TextFlow):void
Language Version : | ActionScript 3.0 |
Runtime Versions : | AIR 1.0, Flash Player 10 |
Disable the spell checking feature for a TLF TextFlow.
Parameters
| comp:TextFlow — TLF TextFlow object on which to disable spell check.
|
public static function enableSpelling(comp:TextFlow, lang:String):void
Language Version : | ActionScript 3.0 |
Runtime Versions : | AIR 1.0, Flash Player 10 |
Enables the spell checking feature for a TLF TextFlow. Once a TextFlow is spell checking enabled, misspelled words will be highlighted with a squiggly line. Users can
right click on a misspelled word to see the suggestions in the context menu.
Parameters
| comp:TextFlow — A TLF TextFlow object
|
|
| lang:String — The language code used for spell checking, for example en_US . it will lookup the SpellingConfig.xml file to access corresponding resource files.
SpellingConfig.xml should located at the same folder as your main mxml source file. You don't have to change the content of this file. However,
if you want to add a new language, to use an alternative dictionary or to customize the location for your dictionaries, you can modify it. There's an known issue with
IIS web server when loading dictionary files with unknown extensions, in which case you can modify the XML to work around it.
|
Example public static function getSpellingMenuEntries():Object
Language Version : | ActionScript 3.0 |
Runtime Versions : | AIR 1.0, Flash Player 10 |
Get the spelling context menu entries.
Returns | Object — A actionScript Object containing the spelling context menu entries. If you haven't customized the entries, you get the default associative array {enable:"Enable Spelling", disable:"Disable Spelling", add:"Add to dictionary"}
|
public static function setSpellingMenuEntries(entries:Object):Boolean
Language Version : | ActionScript 3.0 |
Runtime Versions : | AIR 1.0, Flash Player 10 |
Set the spelling context menu entries. This uses the ActionScript Object class as an associative array for extensibility.
entries
should have all the customized contextMenu entries including enable (spelling),
disable (spelling) and add (to dictionary)
. To ensure a consistent contextMenu within your application,
the spelling context menu entries you provide here are applied to all UI components. We recommend you use this API
to localize the context menu strings.
Parameters
| entries:Object — A Object that looks like entries:Object = {enable:"Enable Spelling", disable:"Disable Spelling",
add:"Add to dictionary"} . If you don't customize the contextMenu, the default contextMenu in English will be used.
|
Returns | Boolean — True if the spelling menu is successfully customized, false if it fails. Possible failure
reasons include passing the wrong object or missing some required entries. If the function fails, the contextMenu is left unchanged.
|
Fri Oct 24 2014, 03:33 PM +11:00