2013-04-23 64 views

回答

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> 
0

您可以聽取change事件以確定項目何時更改。當然,點擊遞增或遞減按鈕並不是唯一的方法來告訴數值何時發生變化。

incrementButton和decrementButton都是skin parts。由於皮膚部件是公開的,因此您可以爲Button click事件添加事件監聽器。

0
protected function spinnerClick(event:MouseEvent):void 
{ 
    Alert.show(event.target.id); 
    // will show 'incrementButton' or 'decrementButton' 
} 

<s:Spinner click="spinnerClick(event)"/>