2 Replies Latest reply on Mar 26, 2010 12:31 PM by solfire

    RichEditableText. Add text when maxHeight is reached

    solfire

      Hi,

       

      Suppose I have a RichEditableText with a maxHeight of 200px. Is there a standard way to stop users entering more text once this value is reached?

       

      Thank you in advance.

        • 1. Re: RichEditableText. Add text when maxHeight is reached
          Flex harUI Adobe Employee

          No.  Usually it is done by number of chars since you can get out to 200px

          really quickly if you have newlines in the content

          • 2. Re: RichEditableText. Add text when maxHeight is reached
            solfire Level 1

            Okay. But I guess number of chars is not safe once I change styles. 200px was an example, so could be lots more. But thank you anyway.

             

            This is what I came up with. Until now it is working very nicely. It relies on undo. I guess I could make this even better. But for now it works. I hope it saves some headbreaking for someone else.

             

            A panel with a RichEditableText:

             

                <s:Panel x="319" y="262" width="250">
                    <s:RichEditableText id="EditText" text="RichEditableText"  percentWidth="100" maxHeight="200"
                                    focusThickness="8" change="EditText_changeHandler(event)" changing="EditText_changingHandler(event)">
                 
                </s:RichEditableText>
                </s:Panel>

             

                  protected function EditText_changingHandler(event:TextOperationEvent):void
                  {
                    var myText:RichEditableText = RichEditableText(event.currentTarget);
                    var myEdit:EditManager = EditManager(myText.textFlow.interactionManager);
                    myEdit.undoManager.pushUndo(event.operation);
                  }

             


                  protected function EditText_changeHandler(event:TextOperationEvent):void
                  {
                    var myText:RichEditableText = RichEditableText(event.currentTarget);
                    var myEdit:EditManager = EditManager(myText.textFlow.interactionManager);
                   
                    var i:Number = myText.contentHeight;
                    var j:Number = myText.maxHeight;
                   
                    if (i > j) {
                      myEdit.undoManager.undo();
                    }
                  }

             

            The changing event occures before the operation is performed, so it is a good moment to "save" the operation as an undo (pushUndo). Next I do a test once the text is added. If the contentHeight goes above maxHeight (or Height if you wish) than the most recent undo is performed.