0

如何检测是否在 Flex Spinner 组件中单击了递增或递减按钮?

4

3 回答 3

1

numericStepper 创建完成后,获取按钮并监听事件:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;

            protected function numericstepper1_creationCompleteHandler(event:FlexEvent):void
            {
                var stepper:NumericStepper = NumericStepper(event.target);

                stepper.incrementButton.addEventListener(MouseEvent.CLICK, onIncrementClickHandler, false, 0, true);
                stepper.decrementButton.addEventListener(MouseEvent.CLICK, onDecrementClickHandler, false, 0, true);
            }

            protected function onIncrementClickHandler(event:MouseEvent):void
            {
                Alert.show("incrementButton click");    
            }

            protected function onDecrementClickHandler(event:MouseEvent):void
            {
                Alert.show("decrementButton click");        
            }

        ]]>
    </fx:Script>

    <s:NumericStepper creationComplete="numericstepper1_creationCompleteHandler(event)" />

</s:Application>
于 2013-04-24T08:15:24.067 回答
0

您可以侦听更改事件以判断项目何时更改。当然,单击递增或递减按钮并不是判断值何时发生变化的唯一方法。

incrementButton 和 decrementButton 都是皮肤部件。由于皮肤部件是公开的,您可以为按钮单击事件添加事件侦听器。

于 2013-04-23T23:12:08.310 回答
0
protected function spinnerClick(event:MouseEvent):void
{
    Alert.show(event.target.id);
    // will show 'incrementButton' or 'decrementButton' 
}

<s:Spinner click="spinnerClick(event)"/>
于 2013-04-24T15:12:56.997 回答