Reputation: 21924
I need to set the text field autosize property to NONE to ensure that HTML links do not jump on rollovers.
However, when I do this, how can I set the textfield height property to show all of the text without scrolling?
I have tried the following but for a reason I cannot figure out, it's squishing the height of my text:
htmlTextField.autoSize = TextFieldAutoSize.LEFT;
htmlTextField.htmlText = htmlText;
var recordedHeight:Number = htmlTextField.textHeight;
htmlTextField.autoSize = TextFieldAutoSize.NONE;
htmlTextField.height = recordedHeight + htmlTextField.getTextFormat().leading + 1;
Upvotes: 2
Views: 4360
Reputation: 6402
If you go here and read.
you will see.
Returns flash.text:TextFormat — The TextFormat object that represents the formatting properties for the specified text.
Now if you look at TextFormat You will see the defaults are all pretty much 0
I ran into this issue a long time ago and the only work around I found was to select some text then grab defaultTextFormat and then deselect the text.
I am sure there is another method to do this but like I said it was my hack-a-round.
Upvotes: 0
Reputation: 8834
TextFields have a 2px gutter all the way around so this may be tripping you up.
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(frameRate="30", backgroundColor="#FFFFFF", width="500", height="500")]
public class TextfieldHeight extends Sprite
{
public function TextfieldHeight()
{
var textFormat:TextFormat = new TextFormat();
textFormat.size = 11;
textFormat.font = "Georgia";
var htmlTextField:TextField = new TextField();
htmlTextField.setTextFormat( textFormat );
htmlTextField.width = 250;
htmlTextField.border = true;
htmlTextField.wordWrap = true;
htmlTextField.autoSize = TextFieldAutoSize.NONE;
htmlTextField.htmlText = '<a href="http://www.google.com">Lorem ipsum dolor</a> sit amet, consectetur adipiscing elit. Aliquam sodales, eros at convallis viverra, risus mauris euismod tortor, ac imperdiet sem augue vitae risus. Morbi ut sem neque. Vestibulum accumsan posuere augue, eu consectetur nibh porttitor eget. Sed suscipit sodales dui id pharetra. Vivamus quis hendrerit lectus. Vivamus interdum, felis a convallis dictum, libero erat aliquet massa, non placerat neque augue quis lacus. Aliquam viverra sem ultrices leo lacinia eu dignissim dolor ullamcorper. Etiam ullamcorper tincidunt velit, a vulputate sapien consequat quis.';
htmlTextField.height = htmlTextField.textHeight + 4;
this.addChild( htmlTextField );
}
}
}
Upvotes: 3