2011-04-19 33 views
2

我想在ActionScript中将一些文本嵌入到圆中。我有三个问题:我无法将文本置于圆圈中央,无法使文本居中对齐,也无法将字体应用于文本。关于字体,我知道它嵌入正确,因为它在舞台上创作的TextField上。在形状中嵌入文本

[Embed(source="DAXCOMPL.TTF", fontName="DaxCompact-Light", mimeType='application/x-font', embedAsCFF='false')] 
private var MyFont:Class; 

public function Bubble(...) { 
    var myFont:Font = new MyFont(); 

    var myFormat:TextFormat = new TextFormat(); 
    myFormat.size = 20; 
    myFormat.align = TextFormatAlign.CENTER; 
    myFormat.font = myFont.fontName; 

    var circle:Sprite = new Sprite(); 
    var r:int = 30; 
    var text:TextField = new TextField(); 
    text.text = "Hello world!"; 
    text.wordWrap = true; 
    text.defaultTextFormat = myFormat; 
    text.autoSize = TextFieldAutoSize.LEFT; 
    text.x = -30; 
    text.y = -30; 

    circle.graphics.lineStyle(2, 0x000000, 1.0); 
    circle.graphics.drawCircle(0,0,r); 
    circle.graphics.endFill(); 
    circle.addChild(text); 
    circle.x = 75; 
    circle.y = 450; 
    addChild(circle); 
} 

回答

1

尝试initalize文本字段是这样的:

var text:TextField = new TextField(); 
text.embedFonts = true; // use embedded font 
text.defaultTextFormat = myFormat; // use this command before setting text 
text.text = "Hello world!"; 
text.wordWrap = true; 
text.autoSize = TextFieldAutoSize.LEFT; 
text.x = -text.textHeight*0.5; //center the textfield after setting text 
text.y = -text.textWidth*0.5; 
+0

对不起,我在回答延迟,但是这解决了两个我的三个问题(垂直对齐我的文字和运用我的字体)。但是,文字仍然没有与形状的中心对齐 - 它总是结果太靠右。这对你有用吗? – 2011-05-04 16:55:16