0

これでうまくいくと思った...

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()のコードを(独自の関数としてではなく)メインコードに配置しましたが、正常に機能します。私はそれを間違って渡しますか?

4

1 に答える 1

3

defaultTextFormatを変更する前に設定する必要がありますtext。getText 内の TextFieldを設定しているためtext、効果はありません。

これを試して :

var bFormat:TextFormat, bStartText:TextField, bQuitText:Textfield;

bFormat = getFormat();

bStartText = getText("Start",bFormat);

bQuitText = getText("Quit",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:String, tf:TextFormat):TextField {
  var bText:TextField = new TextField();
  bText.defaultTextFormat = tf;
  bText.text = sText;
  bText.x = -4;
  bText.y = 4;
  return bText;
}

すでに設定されているテキストフィールドのフォーマットを変更したい場合はsetTextFormatTextFieldクラスで使用できます。

于 2013-03-18T20:24:09.407 に答える