2013-02-25 79 views
0

我需要能夠在禁用的複選框上顯示工具提示。我在這裏看到的關於stackoverflow和其他地方的解決方案是將複選框包裝在一個組中,併爲組提供工具提示。這有效,但我試圖做到這一般。Flex禁用複選框工具提示

我希望能夠在自定義複選框組件上設置屬性,並在此時將Chexbox包裝在具有工具提示的組中。

我的問題是,我不知道如何在複選框ActionScript代碼中的運行時將複選框添加到組組件。我試着加入showDisabledToolTip屬性CheckBox類,做這樣的事情時設置:

var parent = this.parent; 
    var gp:Group = new Group(); 
    gp.toolTip = this.toolTip; 
    gp.addElement(this); 
    if(parent is Group) { 
     parent.addElement(gp); 
    } else { 
     parent.addChild(gp); 
    } 

我在這一點上的主要問題是this.parent爲空。除此之外,我甚至不知道這是否真的有效。

幫助表示讚賞。謝謝!

回答

0

我想出的溶液與2個內新SkinStates(disabledWithTooltip和disabledWithTooltipSelected)

擴展複選框類增加了一個新disabledWithTooltip屬性和覆蓋getCurrentSkinState方法和延伸CheckBox類並創建一個新CheckBoxSkin mouseEventHandler自ButtonBase

自定義CheckBox類


package components 
{ 

    import flash.events.Event; 
    import flash.events.MouseEvent; 

    import mx.events.FlexEvent; 

    import spark.components.CheckBox; 

    [SkinState (disabledWithToolTip)] 
    [SkinState (disabledWithToolTipSelected)] 

    public class CustomCheckBox extends CheckBox 
    { 
     private var _disabledKeepToolTip:Boolean = false; 

     public function CustomCheckBox() 
     { 
      super(); 
      this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete, false, 0, true); 
     } 

     protected function onCreationComplete(ev:FlexEvent):void { 
      //_storedState = this.currentState; 
     } 


     protected override function getCurrentSkinState():String { 
      if(!_disabledKeepToolTip) 
       return super.getCurrentSkinState(); 
      else { 
       if(!selected) 
        return "disabledWithToolTip"; 
       else 
        return "disabledWithToolTipSelected"; 
      } 
     } 

     protected override function mouseEventHandler(event:Event):void { 
      var skinState:String = getCurrentSkinState(); 

      if(skinState != "disabledWithToolTip" && skinState != "disabledWithToolTipSelected") { 
       super.mouseEventHandler(event); 
      } 
     } 
     [Bindable] 
     [Inspectable(category="General", enumeration="true,false", defaultValue="true")] 
     public function get disabledKeepToolTip():Boolean { 
      return _disabledKeepToolTip; 
     } 

     public function set disabledKeepToolTip(value:Boolean):void { 

      _disabledKeepToolTip = value; 

      this.invalidateSkinState(); 
     } 

    } 
} 

創建基於(火花)CheckBoxSkin一個新的皮膚和改變hostcompo NENT在元數據

[HostComponent( 「components.CustomCheckBox」)]

並添加兩個新skinStates

<s:State name="disabledWithToolTip" stateGroups="disabledStates" /> 
<s:State name="disabledWithToolTipSelected" stateGroups="disabledStates, selectedStates" /> 

使用例如

<s:HGroup> 
    <components:CustomCheckBox id="custom_chk" label="KeepTooltipCheckbox" skinClass="skins.CustomCheckBoxSkin" toolTip="See this tooltip"/> 
    <s:CheckBox id="enable_chk" label="enable/disable" change="{custom_chk.disabledKeepToolTip = enable_chk.selected}"/> 
</s:HGroup> 

你必須去適應自己的封裝結構,如果是不同的...