views:

46

answers:

3

When outputting links dynamically, I cannot determine the Y-Pos dynamically. It will work find if my links are single lined.

link_txt.y = i*20;

this will only work if the links are Single Lined. assuming they are 15px for height + 5 for spacing.

As soon as they are 2 lines, they overlap. I've tried different methods but unable to figure it out.

Any ideas?

A: 

I believe what you are looking for is TextField's textHeight property.

LiveDocs TextField textHeight

Dane
I will try these out.
+2  A: 

If by "outputting links" you mean making a vertical list of links as implied by your code snippet, you could try something like this:

var field:TextField;
var prev:TextField;

for( var i:int = 0; i < _fields.length; i++ )
{
   field = _fields[i]
   field.y = prev ? ( prev.y + prev.height ) + padding : 0;
   prev = field;
}

The trick here is that the single line conditional will check to see if there is a valid reference to the prev var. If there it is will set the y position of the current field in the loop to the prev fields y + it's height + padding ( optional ). If there isn't a valid reference to the previous field then it will set the fields y to 0.

jeremynealbrown
A: 
var offsetY : Number = 0;
for (var i : int = 0; i < links.length; i++) {   
 var link_txt : TextField = TextField(links[i]);
 link_txt.autoSize = TextFieldAutoSize.LEFT;
 link_txt.text = "http://www.google.be";
 link_txt.y = offsetY;   
 offsetY += (link_txt.height + 5);   
 addChild(link_txt); 
}
yens resmann
WOW! Thank you! your code worked!!!!!