I'm trying to add the tab key functionality in a rich text editor using the event keyDown. Just to be clear, on a tab key, I need the control to remain in the same text box with '\t' spaces ahead and not skip to the next object. The following code that I tried works perfectly with a textArea but not with RichTextEditor. Am I missing something?
<mx:RichTextEditor width="90%"
height="274"
id="richTextArea"
htmlText="{chapterContent}" keyDown="onTabPress(event);"/>
The keyboard tab key is then handled at the script level as shown.
private function onTabPress(eventkey:KeyboardEvent):void
{
switch(eventkey.keyCode)
{
case Keyboard.TAB:
var indexBegin:int = eventkey.currentTarget.selectionBeginIndex;
var range:TextRange = new TextRange(eventkey.currentTarget as UIComponent,false,indexBegin,indexBegin);
range.text = "\t";
var indexNext:int = eventkey.currentTarget.selectionBeginIndex+range.text.length;
eventkey.currentTarget.setSelection(indexNext, indexNext);
focusManager.moveFocus(FocusRequestDirection.BACKWARD);
break;
}
}
Thanks for all the help.