2013-02-25 160 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> 

你必须去适应自己的封装结构,如果是不同的...