Jul 15, 2009

Autosize and Width sequence of TextField

Have you ever encountered a problem where you are entering text in a TextField however it is not showing up?
Happend to me today for this code:
var txt:TextField = new TextField();
txt.text = "This is my sample text. check this out.";
txt.width = 500;
txt.height = 24;
txt.autoSize = "left";


Do you catch what is the problem?
Let me tell you, it is nothing but a silly mistake. I am setting "width" before "autoSize" and that is what creating problem. So what actually happens when you use the same order is that ActionScript invalidate the width of a TextField after setting autoSize and make the width to 1-3 pixels only.
This problem can easily be solved like this:

var txt:TextField = new TextField();
txt.text = "This is my sample text. check this out.";
txt.autoSize = "left";
txt.width = 500;
txt.height = 24;

No comments:

Post a Comment

I love comments.