0
votes

i'm converting code project from Flash AS 3 to Flex 4. I've got a problem with TextField controls. The text that is placed in it doesn't appear. I've checked it thoroughly and its width is always equal to 4. No matter what text is placed in it, it is always so narrow. I know that in Flex, I should provide width and height explicitly for all the components but there are some issues:

  1. I don't know initial size of such a field - I want it to automatically determine its size based on text that it stores
  2. There is a couple of other containers that contain it and they should resize automatically too, so they have correct size to display all the content of TextField.

Thanks

2

2 Answers

1
votes

First, I'll assume you're using UITextField. If not, use that one.

Having that out of the way, set autoSize property to TextFieldAutoSize.RIGHT, and leave the width undefined. If you have text with multiple lines, or text that won't fit in a line but you want it all displayed, you'll want to set the width of the field to a percentage, usually 100% (percentageWidth from actionscript, width from mxml), and leave the height undefined.

If there are any containers that need to be resized, I'd recommend using VBox/HBox instead of whatever you're using and leaving widths (and possibly heights) also undefined on them.

Labels are components that use TextFields already setup in such a way as to resize themselves on one line only. Even if you don't want to use them you can check their source code.

Text component is similar to Label but allows multiple lines. Again, I advise checking out their source code.

0
votes

Maybe you should use a label or textinput instead of a textfield. Something like <s:Label text="my text" /> by example.