所以我被要求用键盘触发上/下旋转器点击,但我无法找到发送事件的位置......
这就是我的尝试:
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));
}
微调器有一个通用的处理程序,它使用微调器的结果值交换数据网格上的行,发送一个对我来说听起来最干净的解决方案。
EDIT2:
点击处理程序:
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)" />
答案 0 :(得分:1)
不要在皮肤上引用incrementButton / decrementButton。在组件类上执行此操作。
var item:Object=spinner;
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));
事件可能正确调度,但没有事件侦听器正在侦听皮肤实例;所以不会对底层组件进行任何更改。