ボタンを押した後に編集できるテキストフィールドがあります。
playerName = new TextField();
playerName.autoSize = "left";
playerName.styleSheet = styleSheet;
playerName.type = TextFieldType.DYNAMIC;
playerName.tabEnabled = false;
playerName.maxChars = 14;
playerName.background = false;
playerName.backgroundColor = 0x1e904b;
...
var boldStyleObject:Object = {};
boldStyleObject.fontSize = 12;
boldStyleObject.fontFamily = "Verdana";
boldStyleObject.color = "#ffffff";
boldStyleObject.fontWeight = "bold";
styleSheet.setStyle(".bold", boldStyleObject);
boldStyleName = "bold";
...
playerName.htmlText = "<span class='" + boldStyleName + "'>" + player.name + "</span>";
...
private function ChangeName (event:Event):void
{
playerName.type = TextFieldType.INPUT;
playerName.background = true;
playerName.addEventListener(KeyboardEvent.KEY_DOWN, DoneEditing);
stage.focus = playerName;
}
...
private function DoneEditing (event:KeyboardEvent):void
{
var target:TextField = event.target as TextField;
if (event.keyCode == 27)
{
target.text = editBackup;
DisactivateTextField(target);
}
else if (event.keyCode == 13 && target == playerName && playerName.text.length > 3)
{
DisactivateTextField(target);
}
}
private function DisactivateTextField(field:TextField):void
{
field.type = TextFieldType.DYNAMIC;
field.background = false;
field.removeEventListener(KeyboardEvent.KEY_DOWN, DoneEditing);
}
TextFieldの編集可能性を除いて、すべて正常に機能しています。なんで?