Reputation: 676
I have a textinput component on my stage with an instance name of "myTxt"
I would like to add some left padding to the contents of this textfield. I've tried:
myTxt.setStyle("textPadding", 5);
But it adds top (and I assume bottom and right) padding in addition to the left padding. What is the best way to simply add left padding to the textfield's contents?
Thanks for your help!
Upvotes: 1
Views: 5689
Reputation: 11
I've been troubled with this issue.
When you apply text to the field, it resets the vertical position. To apply vertical positioning do it AFTER you put content into the field
Upvotes: 1
Reputation: 1098
You use a TextFormat object for this.
var tf:TextFormat = new TextFormat();
tf.leftMargin = 5;
// if you have a bunch of special formatting for your TextField (fonts/sizes/etc )
// you will need to set it up here.
// If you just using the default text etc you don't need to do anything else.
// you can use defaultTextFormat so you don't ever have to worry about it.
// Just set it up once and it will keep the same formatting.
myTxt.defaultTextFormat = tf;
Edit: Added links to TextField and TextFormat
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html
Update: For a TextInput
import flash.text.TextFormat;
var tf:TextFormat = new TextFormat();
tf.leftMargin = 5;
myTxt.setStyle("textFormat", tf);
Upvotes: 6
Reputation: 1243
You could just move the TextField instance inside the component.
componentName.textField.x += 5;
Upvotes: 1