1 Reply Latest reply on Jul 25, 2007 12:50 PM by Gil1

    RichTextEditor: How to get HTMLText added only

    Gil1
      Using The RichTextEditor, I want to get the HTML text only for the text displayed in the TextArea without all the other styling.
      Example:

      If I type: "I want to learn to fly"
      and mark learn as bold, I want the HTML text to be:

      "I want to <b>learn</> to fly"

      but I get:
      "<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">I want to <B>learn</B> to fly</FONT></P></TEXTFORMAT>"

      The extra styling in conflicting with the CSS that I have, so that's why i don't want that.

      Thanks,

      Gilbert
        • 1. Re: RichTextEditor: How to get HTMLText added only
          Gil1 Level 1
          Well I found a solution. I don't thing is the best one, but it works.
          Here is the code:

          <?xml version="1.0"?>
          <!-- textcontrols/RTERemoveAlignButtons.mxml -->
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script><![CDATA[
          public function removeAlignButtons():void {

          rt1.toolbar.removeChild(rt1.alignButtons);
          rt1.toolbar.removeChild(rt1.colorPicker);
          rt1.toolbar.removeChild(rt1.fontFamilyCombo);
          rt1.toolbar.removeChild(rt1.fontSizeCombo);
          rt1.toolbar.removeChild(rt1.linkTextInput);
          //rt1.toolbar.removeChild(rt1.textArea);
          }

          public function replaceText():void
          {
          var text1:String = '<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">';
          var text2:String = "</FONT></P></TEXTFORMAT>";
          rteText.text = rt1.htmlText;
          for(var i:int=0; i<= 50; i++){
          rteText.text = rteText.text.replace(text1, "");
          rteText.text = rteText.text.replace(text2, "");
          }
          }
          ]]></mx:Script>

          <mx:RichTextEditor id="rt1" title="RichTextEditor With No Align Buttons"
          creationComplete="removeAlignButtons()"/>

          <mx:RichTextEditor id="rt2" title="Default RichTextEditor"/>
          <mx:TextArea id="rteText" width="80%" height="25%"/>

          <mx:HBox>
          <mx:Button label="Show Plain Text" click="rteText.text=rt1.text;"/>
          <mx:Button label="Show HTML Markup" click="{replaceText()}"/>
          </mx:HBox>
          </mx:Application>

          The for loop is very inefficient because is looping 50 times independently of the number of paragraphs on the text. So this can be improved. However, I wanted to post the draft solution in case someone else might need it.

          Gilbert