Solved

Is it possible to set the minimum height of a text field to a value other than 100, a la CSS min-height property?

Posted on 2008-06-19
2
658 Views
Last Modified: 2013-11-11
In CSS/HTML a div may be given a minimum height and be allowed to expand past that. With text fields in AS3 the minimum value is 100, and if the word wrap property is set, the field is allowed to expand vertically past that value. I am trying to position something relative to the bottom of a text field that word wraps:

var someText:String = <<string of arbitrary length and composition>>;
var v1:Something = new Something();
var v2:TextField = new TextField();
v2.wordWrap = true;
v2.text = someText;
v1.y = v2.y + v2.height + 20;

In the scenario above, the object v1 is correctly displayed 120 pixels below the anchor of v2. However, the text only occupies maybe 30 of the 100 pixels allotted to the TextField. When the height of v2 is specifically set to 30, the object v1 shows up ~20 pixels below v2 as desired, but as text wraps the text is hidden. Is there a way to set up the desired behavior?
0
Comment
Question by:ckoning
2 Comments
 
LVL 4

Accepted Solution

by:
emphaticDigital earned 125 total points
ID: 21827939
Hello,

Firstly, AS3 only implements CSS version 1, which means no min-height property.

I'm not sure I understand exactly what your problem is but ... textFields have a property called, 'textHeight', (also textWidth). This property cannot be set but you might be able to use it to solve your problem with the following code:

var t:TextField = new TextField();

addChild(t);

//force text to wrap
t.width = 50;

//make sure the field is too small to show all the text initially
t.height = 50;

//must set wordWrap explicitly
t.wordWrap = true;

//add a border to visualize the size of the field
t.border = true;

//set text
t.text = 'sometext, actually some really long text that has to wrap';

//get the height of the last line of text
var metrics:TextLineMetrics = t.getLineMetrics(t.getLineIndexOfChar(t.length-1));

//set new height for the textField
t.height = t.textHeight+metrics.height;

The last two lines require some explanation. If you comment out the last line, you will see that half of the text is cut off. If you just set the 'height' to the 'textHeight', the last line of text will not show. (I don't know if this is a AS3 glitch or not). To show the last line, you need to get the height of the last line in the paragraph with a TextLineMetrics object and add that to the height as well.

I tested this code and it works to stretch the text box to the correct size to show all of the text. I hope it solves your problem.

Good luck.

Emphatic
0
 
LVL 4

Author Closing Comment

by:ckoning
ID: 31468952
Thank you! Your solution put me on the right track to working around this problem.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question