1 Reply Latest reply on Feb 21, 2010 9:36 PM by Flex harUI

    Issue sizing an UITextfield




      For some self measurement code I want to write ( similar to the typicalItem of Flex4's layout )  I create a temporary UITextfield just to get its measurements. I then apply those measurements to the actual textfield, as seen on the code below :


      var typicalTf : UITextField = createTextField();
      typicalTf.text = "MMM";


      canvas.addChild( typicalTf );
      var tf : UITextField = createTextField();
      canvas.addChild( tf );
      tf.width = typicalTf.measuredWidth; // Works nicely when adding +3

      tf.height = typicalTf.measuredHeight;
      canvas.removeChild( typicalTf );


      ------------------------------------------------------------------------------------------ --------------


      private function createTextField() : UITextField
         var tf : UITextField = new UITextField();
         tf.type = TextFieldType.INPUT;
         tf.selectable = true;
         tf.ignorePadding = true;
         return tf;


      ------------------------------------------------------------------------------------------ --------------


      Using the example above, If I type MMM inside tf, the textfield will start to scroll, indicating it's missing some space. If I had +3 to typicalTf.measuredWidth, it seems to always be working though ( I tried with different combinations of text, font size, family )

      So what is this magic number ? UITextfield is already adding +5 to the textWidth for the measuring of its width.