3 Replies Latest reply on Sep 8, 2009 10:41 AM by Andrew Rosewarn

    How to implement a common RichText editor for multiple TextAreas

    DilipShah Level 1
      In the Flex RichTextEditor  component, TextArea is tightly coupled with the controls that allows you to  format text entered in the TextArea. So, if you wish to format text in multiple  TextAreas using just one set of controls to format their text, it looks like one needs to  rewire the entire component.

      Has anyone done this kind of work so that others  don't need to reinvent the wheels?

      Is Adobe planning on developing RichTextEditor with the new component architecture that will make such functionality easier to implement?
      Dilip

        • 1. Re: How to implement a common RichText editor for multiple TextAreas
          Andrew Rosewarn Level 3

          Hi

           

          You need to look at the TextRange class which allows you to get areas of text and format them.  Quick example

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" creationComplete="init()">

          <mx:Script>

          <![CDATA[

          import mx.controls.textClasses.TextRange;

          private var textSelection:TextRange;

           

          private function init():void {

          textSelection = new TextRange(ta,true);

          }

           

          private function makeBold():void {

          if(textSelection.fontWeight == "bold") {

                   textSelection.fontWeight = "normal";

                 } else {

                   textSelection.fontWeight = "bold";

                 }

          }

          ]]>

          </mx:Script>

           

          <mx:TextArea id="ta" x="78" y="83" width="443" height="179"/>

          <mx:Button x="78" y="279" label="Bold" click="makeBold()"/>

          </mx:Application>

           

          Hope it helps

           

          Andrew

          1 person found this helpful
          • 2. Re: How to implement a common RichText editor for multiple TextAreas
            DilipShah Level 1

            Andrew,

             

            Thanks for pointing me to TextRange class and the example.

             

            So, if I wish to have all the functionality that RichTextEditor offers, I'll have to implement them (hyperlinks, bullets, etc) myself. I was hoping for an easier solutions!

             

            Dilip

            • 3. Re: How to implement a common RichText editor for multiple TextAreas
              Andrew Rosewarn Level 3

              Hi

               

              Yea.  It seems to me you'd need to build a custom component.  It would need your visual controls, and format text according to whatever to clicked.  Cound like a good one to build, RTE controls that you can bind to data sources.

               

              I kind of agree with what you say though it would be nice it the rich text editor was just a bunch of buttons to could target any other text based component with.

               

              Andrew