AS3 Flash change combobox value cause keydown events are disabled

回眸只為那壹抹淺笑 提交于 2019-12-11 22:33:20

问题


I'm using Flash Pro CS6.

I created a fla project and put in a ComboBox. Then i place following code in action:

import flash.events.KeyboardEvent;

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
this.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

function onKeyDown(e:KeyboardEvent)
{
    trace("Keydown :" + e.charCode);
}

function onKeyUp(e:KeyboardEvent)
{
    trace("Keyup :" + e.charCode);
}

both event work fine at the beginning but when i change the ComboBox value, the event KEY_DOWN no longer work.

here is my sample project: Untitled-1.fla


回答1:


As Baris said, you should use stage.focus = null after selecting combobox element :

cb.addEventListener(Event.CHANGE, cb_on_change)
function cb_on_change(e:Event):void {
    stage.focus = null
}

Click anywhere on the stage dont solve problem if there is no element on the stage that will receive the focus.




回答2:


When you click on the combobox it gets focus which prevents keyboard events from firing on the stage.

Do they start working again if you click anywhere on the stage. Alternatively you can clear the focus with stage.focus = null.



来源:https://stackoverflow.com/questions/26540150/as3-flash-change-combobox-value-cause-keydown-events-are-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!