2011-11-21 2 views
1

확인란을 선택 취소하면 사용자에게 확인 상자를 표시하려고합니다. 내 코드는 약간의 해킹이라고 생각하지만 작동합니다. 확인란을 클릭 한 다음 알림을 표시합니다. 결과에 따라 나는 체크 박스를 다시 체크하도록 설정한다.플렉스 확인란을 선택하고 예/아니요 상자를 선택 취소합니다.

내 코드가 나는이

  1. 코드에 대해 좋아하지 않는 두 가지 CB1에 고유하고 확인란을 선택 취소
  2. 다른 확인란 다시 사용할 수 없습니다

    <?xml version="1.0"?> 
    <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" > 
    <fx:Script><![CDATA[ 
        import mx.controls.Alert; 
        import mx.events.CloseEvent; 
    
        private function handleCheckBoxChange(e:Event):void { 
         if (!CheckBox(e.target).selected) { 
          Alert.show("Are you sure you want to deselect?", "Confirm", 
           Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES); 
         } 
        } 
    
        public function handleAlert(event:CloseEvent):void { 
         if (event.detail == Alert.YES) { 
          trace("yes clicked"); 
         } 
         else if (event.detail == Alert.NO) { 
          cb1.selected = true; 
          trace("no clicked"); 
         } 
        } 
        ]]></fx:Script> 
    
        <s:CheckBox id="cb1" label="cb1" click="handleCheckBoxChange(event)"/> 
    </s:NavigatorContent> 
    

    입니다 경고가 표시되면. 그런 다음 사용자가 아니오를 클릭하면 확인란이 다시 선택됩니다.

사용자가 경고 상자에서 아니오를 클릭하면 선택 취소 이벤트를 중지하는 것이 이상적입니다. Flex에서 이것을 가로 챌 수 있습니까?

감사합니다.

답변

2

두 가지 문제에 대한 한 가지 해결책 : CheckBox를 확장하는 사용자 지정 클래스를 만듭니다. 나중에 click 이벤트에 e.stopImmediatePropagation()을 사용할 수 없기 때문에 이벤트를 추가 할 수 없습니다. 그러나 추적하면 ToggleButtonBase (상위는 CheckBox)에는 buttonReleased이라는 보호 된 함수가 포함되어 있습니다. 이 함수는 selected 값에 대한 변경을 수행하고 change 이벤트를 전달합니다. 새로운 클래스에서해야 할 일은이 함수를 재정의하는 것입니다.

public class AlertCheckBox extends CheckBox 
    { 
     public function AlertCheckBox() 
     { 
      super(); 
     } 

     override protected function buttonReleased():void 
     { 
      if (selected) { 
       Alert.show("Are you sure you want to deselect?", "Confirm", 
        Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES); 
       return; 
      } 

      super.buttonReleased(); 
     } 

     public function handleAlert(event:CloseEvent):void { 
      if (event.detail == Alert.YES) { 
       selected = false; 
      } 
     } 
    } 
+0

훌륭한 우수 답변 해리. 감사 – RNJ

관련 문제