0

所以我被要求用键盘触发向上/向下微调器点击,但我找不到在哪里调度事件......

这是我尝试过的:

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)" />
4

1 回答 1

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));

事件可能正在正确调度,但没有事件侦听器正在侦听皮肤实例;因此不会对底层组件进行任何更改。

于 2013-04-12T01:23:25.650 回答