views:

13

answers:

1

Hi, I have custom components which must adjust their text content based on space constraints. For example a component adds labels until there is no space, and then the content of the last label becomes "(x more)" I do not have access to size of child controls before adding them. When in updateDisplayList, I make changes to the layout of the component, but for labels, lblInstance.text property fires events, which lead to updateDisplayList being called again. I know that updateDisplayList may be called more than once, but if there is a way to modify text without triggering events, that'd be really useful. For example, setActualSize method in UIComponent allows this kind of modification. Anything similar for text controls? Or do you have best practices for laying out and managing text content, in the context of custom Flex components?

Best Regards Seref

+1  A: 

Use the measure() method to set your text component sizes.

You will probably have to call validateNow() on them so that they will be forced to figure out the actual textWidth and textHeight and return the actual number of lines of text in the textField if they are long enough to wrap. Investigate the TextMetrics class for more ways to measure.

Robusto
Thanks, I've completely forgotten about validateNow. It should help me a lot.