Hi there,
I’m trying to display a range of dynamic textfields, using an array.
I can place everything on the stage fine, but I just can’t figure out the maths behind placing each textfield next to each other horizontally. So, despite the length of the word, the spacing between each textfield is the same, e.g. 10px.
I’m sooooo eager for this one little calculation!
var myArray:Array = new Array("little", "looooooong", "huuuuuuuuuuuuuggeeeeee", "tiny");
var container_mc:MovieClip = new MovieClip();
container_mc.x = 80;
container_mc.y = 60;
addChild(container_mc);
for (var i:int = 0; i < myArray.length; i++)
{
//trace (myArray*);
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.align = TextFormatAlign.CENTER;
myTextFormat.size = 24;
var myText:TextField = new TextField();
myText.autoSize = TextFieldAutoSize.LEFT;
myText.textColor = 0xA60000;
myText.text = myArray*;
myText.selectable = false;
myText.setTextFormat(myTextFormat);
myText.x = 0-myText.width/2*i+myText.width;//<<--- This is the bit I can't figure out!
container_mc.addChildAt(myText, 0);
}
Cheers,
Mark