0 Replies Latest reply on Dec 14, 2006 2:38 AM by DavidWhewell

    TextField width issue

    DavidWhewell Level 1
      Hi there,

      I have a problem with the TextField object. I am changing TextFields dynamically and arranging them in a table structure. Sometimes, the TextField is returning some very strange and inappropriate values for its width property. Let me illustrate:

      Here is how the TextField is initialised:

      text = new TextField();
      text.autoSize = TextFieldAutoSize.LEFT;

      This is the code that updates it:

      public function set contents(s:String):void
      trace("Setting contents to " + s + ", initial width is " + text.width);
      text.text = s;
      trace("Text width after change is " + text.width);

      And here is my debug output:

      Setting contents to 6204.3, initial width is 4
      Text width after change is 149.70000000000002
      Setting contents to 6203.8, initial width is 35.2
      Text width after change is 35.2
      Setting contents to 6203.6, initial width is 35.2
      Text width after change is 35.2

      It seems like for some reason, setting the text with the first value sets the width super wide - 149 pixels! (the value of 35 pixels beforehand is correct). Even stranger, the text width magically changes to 35 pixels between the first and second assignments, even though the TextField is not touched between them.

      Is there some kind of resizing/rendering thing the TextField goes through over time? Is it possible to force this process through, so that I can work with the correct width instead of this intermediary value? The TextField getting really wide is messing with my table layout, obviously.

      Hope someone has a solution to this, it's weird behaviour, but happens every time!

      Thanks in advance,