How to calculate the height of text (width fixed)?
I want to create a text box with a fixed width that will fit itself to its current text. So I went ahead and wrote this simple application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="load();">
<mx:Script>
<![CDATA[
private function load():void {
text1.height = text1.textHeight;
}开发者_Python百科
]]>
</mx:Script>
<mx:TextArea id="text1" x="10" y="10" width="352" height="196" wordWrap="true" text="Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test"/>
</mx:Application>
Alas, the height of textHeight
is twice the height I needed.
How come? and how can it be fixed?
Its a bug!
Heres a workaround: http://www.nbilyk.com/flex-textheight-bug
精彩评论