当我尝试在我的AS3文本字段中使用对齐时,我得到一个奇怪的错误

时间:2015-12-10 16:35:09

标签: actionscript-3 actionscript

所以我正在尝试使用align来集中文本域中的文本

var inputFieldOne:TextField= new TextField();
        inputFieldOne.width= 150;
        inputFieldOne.height= 50;
        inputFieldOne.x= 180;
        inputFieldOne.border= true;
        inputFieldOne.type= "input";
        inputFieldOne.restrict= "0-9";
        inputFieldOne.maxChars= 1;
        inputFieldOne.background= true;
        inputFieldOne.backgroundColor= 0x00FF00;
        inputFieldOne.align = TextFormatAlign.CENTER;
        inputFieldOne.defaultTextFormat = new TextFormat("verdana", 45);

我收到此错误:

1119: Access of possibly undefined property align through a reference with static type flash.text:TextField.

帮助?

1 个答案:

答案 0 :(得分:1)

TextField没有align属性。您可能会将其与具有该属性的TextFormat混淆。

尝试以下方法:

var textFormat:TextFormat = new TextFormat("verdana", 45);
textFormat.align = TextFormatAlign.CENTER:

var inputFieldOne:TextField= new TextField();
    inputFieldOne.width= 150;
    inputFieldOne.height= 50;
    inputFieldOne.x= 180;
    inputFieldOne.border= true;
    inputFieldOne.type= "input";
    inputFieldOne.restrict= "0-9";
    inputFieldOne.maxChars= 1;
    inputFieldOne.background= true;
    inputFieldOne.backgroundColor= 0x00FF00;
    inputFieldOne.defaultTextFormat = textFormat;