Sunday, April 4, 2010

Line counts in s:TextInput or s:TextArea

Is there a way to get the number of lines in an s:TextInput or s:TextArea control??I need to write some code that will change font size based on the number of lines so that if the text gets too long, I can make the font smaller so all content fits within the box.

Thanks.

Line counts in s:TextInput or s:TextArea

Please file a bug.

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

Line counts in s:TextInput or s:TextArea

You could try looking to see how many children the RichEditableText in the TextInputSkin or TextAreaSkin has. Each line of text is a subclass of DisplayObject called TextLine. However, some of the children may be Shapes if you are using backgroundColor on %26lt;span%26gt; tags, so if that's an issue you'd have to enumerate the children and check each one.

Gordon Smith

Adobe Flex SDK Team

Actually, you're going to also have the problem that RichEditableText doesn't create TextLines for lines of text that aren't visible.

You should instead look at the contentHeight property of the RichEditableText. If it is greater than the actual height, then the text doesn't fit.

Gordon Smith

Adobe Flex SDK Team

I tried using the contentHeight property, but it wasn't consistently returning the correct value.?Occassionaly, the change event would cause that property to be updated, so I could paste in 4 lines of text and the contentHeight would remain at 0.

I'll post a bug and hope for a fix in the final gumbo sdk.

No comments:

Post a Comment