5 Replies Latest reply on Oct 15, 2010 9:12 PM by raphi-sz

    How to insert text in a mx:TextArea

    raphi-sz

      Hi,

       

      with a spark:TextArea, we have the useful method insertText at the cursor current position.

      But in my case, I must use a mx:RichTextEditor (because there isnt such a component in spark) which uses a mx:TextArea.

      But the mx:TextArea doesnt have the insertText method.

       

      I need this because I want to drag'n'drop a String from a Tree into the TextArea at the cursor current position.

       

      How can I do that?

       

      Thanks!

        • 1. Re: How to insert text in a mx:TextArea
          Flex harUI Adobe Employee

          You can subclass, access the internal TextField and call replaceText

          • 2. Re: How to insert text in a mx:TextArea
            raphi-sz Level 1

            Thanks for the answer.

             

            I try this but now I've got a new problem:

            I changed the mx:TextArea by a MyTextArea that extends the mx:TextArea and added a getter for TextField.

            But now, it seems that the html or text property is no longer mapped.

             

                 public class MyTextArea extends TextArea
                 {
                      public function MyTextArea()
                      {
                           super();
                           this.textField = new UITextField; // because the textField attribute is not accessible
                      }
                      
                      public function getTextField():IUITextField
                      {
                           return textField;
                      }
                 }
            

             

            And the component:

             

            <mx:RichTextEditor id="richEditor"
                              htmlText="{repeatEditor.currentItem[1]}"  << This no longer works
                         initialize="initTextEditor(repeatEditor.currentIndex)"/>
            

             

            I set the textArea in the initTextEditor function.

             

            Why this no longer load the data from {repeatEditor.currentItem[1]} in the htmlText?

            • 3. Re: How to insert text in a mx:TextArea
              Flex harUI Adobe Employee

              There should be no need to create a new UITextField.

              • 4. Re: How to insert text in a mx:TextArea
                raphi-sz Level 1

                I know, but when there is the initialisation of the RichTextEditor, it throw an error (in the RichTextEditor class) because the method getTextField returns null.

                Any idea?

                • 5. Re: How to insert text in a mx:TextArea
                  raphi-sz Level 1

                  I found finally a simplier solution:

                  to access textField property, use that:

                   

                  textArea.mx_internal::getTextField().replaceText...

                   

                  Thanks !