Saturday, December 13, 2008

Flex cookbook beta - How do we display HTML in a Flex application?

Flex cookbook beta - How do we display HTML in a Flex application?

check out the component

Average rating

Blogged with the Flock Browser

Sunday, December 7, 2008

Automatically resize Text/TextArea based on content (autoSize) in Flex

Automatically resize Text/TextArea based on content (autoSize) in Flex

by Nicolas Noben

UPDATE: turns out that doesn’t always work. the autoSize property is not reliable at all…

This, should do!

var ta_height:uint = 25;

field.validateNow();

for(var i:int=0; i < field .mx_internal::getTextField().numLines; i++) {
ta_height += field.mx_internal::getTextField().getLineMetrics(i).height;
}

derivedHeight = ta_height;

Thanks Vaan.


Original post:

Adobe’s dodgy textHeight sure doesn’t do the trick. I end up getting a textfield of 2000px height while it clearly looks like 300 tops.

This, however, works.

the code

private function resizeMe(field:TextArea) :void
{
field.validateNow();
field.mx_internal::getTextField().autoSize = TextFieldAutoSize.LEFT;
field.height = field.mx_internal::getTextField().height;
}

Just use that on your TextArea or Text component:

creationComplete="resizeMe(this.myTextAreaInstance)"

Freelance