Okay, maybe my brain took the weekend off early, but I just can't get
TextFields to cooperate...

(BTW, this is an AS3 Project, so no Label or Text or other UIComponent
suggestions, please!)

I create a TextField:

var text:TextField = new TextField();

That I want formatted like so:

text.defaultTextFormat = new TextFormat("Courier", 18);

And I want the TextField to automatically size itself to its text:

text.autoSize = TextFieldAutoSize.CENTER;

And then, at various points in my program, I change the text:

text.text = "Some text";

What I expect is that the autoSize will adjust the size of my
component so that it *completely* fits my text I set to it without me
having to do anything (at least that's my understanding of "auto").

So, I assume I could throw my TextField to a certain point on the screen:

// centered near the top edge of this DisplayObjectContainer
text.x = this.width / 2;
text.y = 10;

And whenever I updated the text it would remained center along the top
edge of the screen. I assumed it would do this internally by having
the text go to the left of the TextField's position (using text.x and
text.y as a registration point, so to speak). What I discovered,
frustratingly, is that it appears that what it actually does is simply
*change* the x/y values I loving calculated (when autoSize == CENTER)
and modify the width/height (as necessary).

Okay, well I grappled with that by doing this in my update code:

text.text = "";
text.x = this.width / 2;
text.y = 10;
text.text = newTextValue;

This seemed to work... or so it seemed... now, the autoSize seems to
only happen the first time I update the text! So, it sizes just right
to the first value I stick in there, but the second value (which is
longer) gets truncated!

Do I have to reset autoSize each time? What gives? Is there something
I could be doing in my code (save clearing autoSize) that would result
in a TextField truncating its contents? I would assume that if
autoSize is set to anything other than NONE I would *never* have
truncated text, but obviously I'm wrong!

Any ideas?

Troy.


Reply via email to