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
653 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now