flash dynamic text field
I want to make auto width text area. Using xml to pull the data, I would like to expand as data comes in.
menu_item_group["menu_item" + i].item_label = nodes[i].attributes.item_label;
For example: enlarged according to the co开发者_StackOverflow中文版ntext menus in this example, the background http://webscripts.softpedia.com/scriptScreenshots/AS3-XML-MENU---VERTICAL---Screenshots-53313.html
How can I do this?
I cooked up a light example for you. The most important part to note is the myField.autoSize
as that will do what you are looking for. I use LEFT
by default, but there is also CENTER
and RIGHT
. Anyway, in this working example you'll see that the border always fits to the length of the text and that the length is new every time you run the program. Note that this example only works when the TextField
is set to Single Line. Multi Line works differently. Good Luck!
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
var myField:TextField = new TextField();
myField.border = true;
var jibberish:String = "Z";
for(var i=0; i < Math.floor(Math.random() * 100); ++i) jibberish += "Z";
myField.text = jibberish;
myField.autoSize = TextFieldAutoSize.LEFT;
this.addChild(myField);
精彩评论