Search code examples
actionscript-3alignmenttextfield

setting textfield vertical alignment, AS3


textFormat.align = "center";

This, but a vertical equivalent please? Because of my experience with HTML I have tried

textFormat.valign = "middle";

But it does not work


Solution

  • You can't align text vertically automatically in AS3.

    You'll have to write your own function to do this.

    eg.

    public function verticalAlignTF(tf:TextField):void
    {
        tf.y += Math.round((tf.height - tf.textHeight) * .5);
    }
    

    Another option would be using TLFTextField, which has a verticalAlign property. Just note that TLF has been deprecated by Adobe, so you might run into some issues.