开发者

outputting an array of links, with no overlapping!

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开发者_StackOverflow社区?


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.


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); 
}


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

LiveDocs TextField textHeight

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜