1、如果是在mxml里面明确知道有多长的字符串,如 label text=“用户名:”,使用“ \r\n ”。
2、如果在as里面明确知道字符串的长度,如var label:Label = new Label(); label.text="明确知道长度:",这里使用“ 
“。
但是有一种情况,使用label展示平板消息,这样就不能明确text的长度,就会产生...的现实。
重写组件,固定宽度后,实现自动换行。
package common.flash.label
{
import mx.controls.Alert;
import mx.controls.Label;
import mx.core.*;
import flash.text.TextFieldAutoSize;
public class MyLabel extends Label
{
public function MyLabel()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
textField.multiline = true;
textField.wordWrap = true;
textField.autoSize = TextFieldAutoSize.CENTER;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
textField.y = (this.height - textField.height) >> 1;
height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom");
}
}
}