Search code examples
flashactionscript-3actionscriptpaddingtextfield

How can I do padding top and bottom of TextField in actionscript3?


Padding left can be done by TextFormat.leftMargin.
And padding right can be done by TextFormat.rightMargin.

But there is no topMargin or bottomMargin property in TextField or TextFormat.
How can I do padding top and bottom?


Example code of left and right padding(margin) of TextField:

var format:TextFormat = new TextFormat
format.leftMargin = 40
format.rightMargin = 40

var text:TextField = new TextField
text.defaultTextFormat = format
text.background = true
text.backgroundColor = 0xeeaaaa
text.autoSize = TextFieldAutoSize.CENTER
text.text = 'abc'

Solution

  • Just increase the height of your sprite, text.height + 10 for example, and set text.y = 5 for a 5 pixel top and bottom margin