views:

31

answers:

2

Hello everyone I was wonder if anyone knew a way to get a textfields current size?

+1  A: 

In general, the current position, width, and height are stored in:

textfield.x
textfield.y
textfield.width
textfield.height

Though it might not be set until it's positioned within something that's at some point connected to the stage. Otherwise, it hasn't figured out how big it is yet, in case it needs to squeeze into a smaller outer object or something.

You can trap when it's added to the stage with

textfield.addEventListener( mx.events.Event.ADDED_TO_STAGE, handleAddedToStage );
...
protected function handleAddedToStage( event:Event ):void
{
  ...

Update:

User wants text-size. I believe the answer is:

textfield.getTextFormat().size

Where there are optional args to getTextFormat() to pick a range of text within the field.

eruciform
By Size I was referring to the font size. Not the actual size of the textBox. I wonder if this is even possible with textFields that would have two differnt font sizes in it...
updated. let me know how this works, i haven't messed with it much.
eruciform
Thank you getTextFormat() was what I was looking for!
+1  A: 

If you're applying multiple text formats to a TextField, then you might actually be in luck, because AS3 will start to represent the TextField using HTML.

You can get at the HTML by writing:

yourTextField.htmlText

This will give you something like:

<P ALIGN="LEFT">
    <FONT FACE="Georgia" SIZE="12" COLOR="#666666" LETTERSPACING="0" KERNING="0">
        Smaller text.
    </FONT>
    <FONT FACE="Georgia" SIZE="16" COLOR="#666666" LETTERSPACING="0" KERNING="0">
        Bigger text.
    </FONT>
</P>

You could then parse this string and search for the SIZE attributes. In the example above they'd be 12 and 16 pixels.

If you're just applying a single text format, you can go ahead and use eruciform's suggestion:

yourTextField.getTextFormat().size
danyal