以为这会奏效...
var bFormat:TextFormat, bStartText:TextField, bQuitText:Textfield;
bFormat = getFormat();
bStartText = getText("Start");
bStartText.defaultTextFormat = bFormat;
bQuitText = getText("Quit");
bQuitText.defaultTextFormat = bFormat;
stage.addChild(bStarText);
stage.addChild(bQuitText);
function getFormat():TextFormat {
var bFormat:TextFormat = new TextFormat();
bFormat.font = "Arial";
bFormat.color = 0X000000;
bFormat.size = 28;
bFormat.align = "center";
return bFormat;
}
function getText(sText):TextField {
var bText:TextField = new TextField();
bText.text = sText;
bText.x = -4;
bText.y = 4;
return bText;
}
两个文本字段都显示在舞台上,但是我没有得到 getFormat() 中指定的任何格式。我已将 getFormat() 中的代码放在主代码中(而不是作为它自己的函数),它工作正常。我是否错误地通过了它?