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
661 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

636 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