我遇到闪存组件ComboBox的问题。当我不想在ComboBox中保存一个名字时,它总是没有最后一个字母!?
以下是代码:
var input_name:String;
text_field.addEventListener (TextEvent.TEXT_INPUT, text_input);
button.addEventListener (MouseEvent.CLICK, save);
function save (e:MouseEvent):void
{
text_field.visible = true;
text_field.adddEventListener(KeyboardEvent.KEY_DOWN, save_text);
}
function text_input(e:TextEvent):void
{
input_name = text_field.text;
}
function save_text(e:KeyboardEvent):void
{
var keyPressed:String = e.keyCode.toString();
if (keyPressed == "13")
{
combo.addItem({label:input_name, data:input_name});
}
}
因此,当我在文本字段中输入'foo'并按ENTER键时,它会在组合框中保存'fo'...
获答答案:)
答案 0 :(得分:0)
TextEvent.TEXT_INPUT
。
Event.CHANGE
。
这将有效,包括处理输入键。
import flash.events.MouseEvent;
import flash.events.Event;
var input_name:String;
text_field.addEventListener(Event.CHANGE, text_input);
text_field.addEventListener("enter", save);
button.addEventListener(MouseEvent.CLICK, save);
function text_input(e:Event):void
{
input_name = text_field.text;
}
function save(e:*):void
{
text_field.visible = true;
combo.addItem({label:input_name, data:input_name});
}