所以我被要求用键盘触发向上/向下微调器点击,但我找不到在哪里调度事件......
这是我尝试过的:
var item:Object=spinner.skin;
item.incrementButton.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN));
item.incrementButton.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
item.incrementButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
item.decrementButton.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN));
item.decrementButton.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
item.decrementButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
有任何想法吗?
编辑:我必须为数据网格行交换创建快捷方式。
if(e.keyCode==Keyboard.NUMPAD_ADD){
spnOrder.value++;
spnOrder.incrementButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
else if(e.keyCode==Keyboard.NUMPAD_SUBTRACT){
spnOrder.value--;
spnOrder.decrementButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
微调器有一个通用处理程序,它用微调器的结果值交换数据网格上的行,对我来说,发出点击听起来是最干净的解决方案。
编辑2:
点击处理程序:
private function spnOrder_clickHandler(e:MouseEvent):void{
var toIndex:int=spnOrder.value;
var index:int=grid.selectedIndex;
if(toIndex>-1 && toIndex<list.length && index>-1 && toIndex!=index){
if(toIndex<index)
list.addItemAt(list.removeItemAt(index-1),index)
else
list.addItemAt(list.removeItemAt(index+1),index);
grid.setFocus();
grid.setSelectedIndex(toIndex);
}
else{
grid.setFocus();
spnOrder.value=index;
}
}
微调器:
<s:Spinner
id="spnOrder"
value="{grid.selectedIndex}"
skinClass="skins.SpinnerInvertedSkin"
click="spnOrder_clickHandler(event)" />