1 Reply Latest reply on May 10, 2009 4:30 PM by run,ryan!

    Multiple textareas problem

    ShaF10 Level 1

      Hi Guys

       

      My MXML file dynamically creates new text areas when the current one has reached it's limit. The new text area will continue where the previous one stopped. The problem is all properties from the previous textarea are inherited by the new textarea. These properties include the textarea.length and textarea.textHeight. Therefore, the new textarea won't accept any new text and will create a new textarea because it thinks its reached the end of its limit when it hasn't. Please take a look at the code below:

       

      The class:

       

      package myComponents
      {
          import mx.controls.TextArea;
          
          public class DocumentTextArea extends TextArea
          {
              private var pageWidth:int = 300;
              private var pageHeight:int = 300;
              
              public function DocumentTextArea()
              {
                  super();
                  this.verticalScrollPolicy="off";
                  this.horizontalScrollPolicy="off";
                  this.height = pageHeight;
                  this.width = pageWidth;
              }
                      
              public function getPageWidth():int
              {
                  return this.width;
              }
              
              public function getPageHeight():int
              {
                  return this.height;
              }
              
              public function getTextHeight():int
              {
                  return this.textHeight;
              }
      
          }
      }
      

       

      The MXML functions:

       

      private function checkLength(event:KeyboardEvent):void
      {    
          var previousTextArea:DocumentTextArea;
          var textArea:DocumentTextArea = new DocumentTextArea();
          textArea = getDocObj(event.currentTarget.id);
      
          if(event.keyCode == 8 && textArea.length == 0) 
          {
              trace("remove invoked");
              if(event.currentTarget.id != 0) {
                  removeChildTextArea(textArea, event.currentTarget.id);
                  trace("before minus "+event.currentTarget.id+" after "+(event.currentTarget.id-1));
                  previousTextArea = getDocObj(event.currentTarget.id-1);
                  previousTextArea.setFocus();
              }
          }
          else if(event.keyCode == 8 && (textArea.getPageHeight() - textArea.mx_internal::getTextField().height) < (textArea.getPageHeight() - textArea.getTextHeight())) 
          {
              if(event.currentTarget.id != "0") {
                  previousTextArea = getDocObj(event.currentTarget.id-1);
                  previousTextArea.setFocus();
              }
          }
          else if(event.keyCode != 8 && 
              (textArea.getPageHeight() - textArea.mx_internal::getTextField().height) 
              > (textArea.getPageHeight() - textArea.getTextHeight()))
          {
              //create new textarea
              var newtextArea:DocumentTextArea = new DocumentTextArea();
              newtextArea.addEventListener(KeyboardEvent.KEY_UP, checkLength);
              documentContainer.addChild(newtextArea);
              newtextArea.setFocus();
              documentArray.addItem(textArea);
             
              if(documentArray.length == 0) {
                  newtextArea.id = (0).toString();
              } else {
                  documentPointer += 1;
                  newtextArea.id = documentPointer.toString();
              }
          }        
      }
      
      private function getDocObj(id:int):DocumentTextArea
      {
          //trace("array size "+documentArray.length+" and id size is "+(id).toString());
          var findTextArea:DocumentTextArea = DocumentTextArea(documentArray.getItemAt((id)));
          return findTextArea;
      }
      
      
        • 1. Re: Multiple textareas problem
          run,ryan! Level 3
          private function checkLength(event:KeyboardEvent):void
          {   
              var previousTextArea:DocumentTextArea;
              var textArea:DocumentTextArea = new DocumentTextArea();
              //textArea = getDocObj(event.currentTarget.id);
              //change this line to -->
             
          textArea = event.currentTarget as DocumentTextArea;