I'm in the process of extending RichTextEditor component with
"Ctrl-b", "Ctrl-i", and "Ctrl-u" keyboard formatting options.
Conceptually, it's quite simple. For example, "Ctrl-b" will dispatch
a mouse click event from the RichTextEditor's boldButton. However,
the following code will only work if some text is highlighted.
Additionally, this code in debug mode with a breakpoint will always
work.
If you know of a way to address this without adding empty cpu cycles
or rewriting RichTextEditor.mxml file, please let me know.
Thanks.
-----------------------------------------------
note, rte is a RichTextEditor object.
private function InitializeComponent():void
{
rte.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
}
private function keyDown(event:KeyboardEvent):void
{
if ((event.ctrlKey) && (event.charCode == 98)) // "Ctrl-b"
{
rte.boldButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
}
------------------Ugly workaround-------------
private function keyDown(event:KeyboardEvent):void
{
if ((event.ctrlKey) && (event.charCode == 98)) // "Ctrl-b"
{
rte.boldButton.setFocus();
// Add empty cpu cycles
rte.boldButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
}