按照標題,我該怎麼辦?下面是一個最小的工作例子反映了我的情況:如何在使用自定義字體時將TLFTextField中的文本居中?
import fl.text.TLFTextField;
import flashx.textLayout.formats.*;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.edit.*;
var tf:TLFTextField = new TLFTextField();
tf.embedFonts = true;
tf.text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean suscipit semper viverra.';
var format:TextLayoutFormat = new TextLayoutFormat();
format.fontFamily = 'MyPlainFont';
format.fontLookup = FontLookup.EMBEDDED_CFF;
format.fontSize = 14;
format.textAlign = TextAlign.CENTER;
var editManager:EditManager = new EditManager();
var sel:SelectionState = new SelectionState(tf.textFlow, 0, 86);
tf.textFlow.interactionManager = editManager;
editManager.applyLeafFormat(format, sel);
var format2:TextLayoutFormat = new TextLayoutFormat();
format2.fontFamily = 'MyBoldFont';
format2.fontLookup = FontLookup.EMBEDDED_CFF;
format2.fontSize = 14;
format2.textAlign = TextAlign.CENTER;
var sel2:SelectionState = new SelectionState(tf.textFlow, 0, 20);
editManager.applyLeafFormat(format2, sel2);
tf.width = 100;
tf.wordWrap = true;
addChild(tf);
我不會使用TLFTextField,它有問題。 – atilkan 2012-05-06 23:02:06