0 Replies Latest reply on Nov 3, 2009 2:29 AM by arne.beduerftig

    Shortcuts to set styles in RichTextEditor

    arne.beduerftig

      I have been asked to enable the use of shortcuts to set styles in RTE component we are using in our application.

       

      I tried to trigger on KeyboardEvent.Key_DOWN (Cmd + b):

      rte.boldButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
      

      rte shall be the reference to the RTE here.

       

      On releasing the Cmd button the button is "clicked" again and the text format reverted.

      Any clue how I can avoid this? Just know executing the same statement on button.click (a differnt button than the button on control bar of RTE) works.

       

      Here is he complete code of a test project:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
           creationComplete="addEventListener(MouseEvent.CLICK, addListener)">
           
           <mx:Script>
                <![CDATA[
                     import mx.core.EventPriority;
                     
                     private function onKeyDown(event:KeyboardEvent):void 
                     {
                          if(event.ctrlKey && String.fromCharCode(event.charCode) == 'b')
                          {
                               makeBold();
                          }
                     }
                     
                     private function makeBold():void
                     {
                          rte.boldButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
                          trace("bold");
                     }
                     
                     private function addListener(event:MouseEvent):void
                     {
                          stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
                     }
                     
                ]]>
           </mx:Script>
           
           <mx:Button label="bold" click="makeBold()" />
           <mx:RichTextEditor id="rte" title="Title" />
           
      </mx:WindowedApplication>
      
      

       

      Thanks