我有一个文本字段,按下按钮后应该可以编辑:
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 的可编辑性。为什么?