The following example shows how you can enable and disable tool tips globally within a Flex application by setting the ToolTipManager.enabled property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/03/globally-disabling-tool-tips-using-the-flex-tooltipmanager-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.managers.ToolTipManager;

            private function toggleToolTipEnabled():void {
                ToolTipManager.enabled = !ToolTipManager.enabled;
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox label="ToolTipManager.enabled"
                selected="true"
                click="toggleToolTipEnabled()" />
    </mx:ApplicationControlBar>

    <mx:Button id="button"
            label="Roll over me for a tool tip"
            toolTip="The quick brown fox jumped over the lazy dog" />

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

4 Responses to Globally disabling tool tips using the Flex ToolTipManager class

  1. Kris says:

    Took forever for me to search the internet to disable tooltips, and now I see its emberassingly simple. :-)
    Thank you for posting.

  2. DJ says:

    Hello Peter,

    How can i disable the tooltips on the buttons of the buttonbar / togglebuttonbars. I don’t want to disable all the tooltips of the complete application. I have tried numors things but nothing seems to work for me.

    I have tried tooltip = “null” on the togglebuttonbar but it doesn’t effect the buttons on the togglebuttonbar.

    do you know how to do this?

    • Peter deHaan says:

      @DJ,

      I found a solution, but I’m not sure it is ideal as I had to create a custom ButtonBar and ButtonBarButton component and override some default Button logic:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              xmlns:comps="comps.*"
              layout="vertical"
              verticalAlign="middle"
              backgroundColor="white">
       
          <mx:Array id="arr">
              <mx:Object label="The quick brown fox" foo="One" />
              <mx:Object label="Quick brown fox jumps" foo="two" />
              <mx:Object label="Brown fox jumps over" foo="three" />
              <mx:Object label="Fox jumps over the" foo="fopir" />
              <mx:Object label="Jumps over the lazy" foo="five" />
              <mx:Object label="Over the lazy dog" foo="six" />
          </mx:Array>
       
          <mx:Form>
              <mx:FormItem label="default ButtonBar:">
                  <mx:ButtonBar id="bBar" dataProvider="{arr}" width="400" />
              </mx:FormItem>
              <mx:FormItem label="CustomButtonBar:">
                  <comps:CustomButtonBar id="cBBar" dataProvider="{arr}" width="400" />
              </mx:FormItem>
          </mx:Form>
       
      </mx:Application>

      The custom ButtonBar, comps/CustomButtonBar.as, is as follows:

      package comps {
          import comps.CustomButtonBarButton;
       
          import mx.controls.ButtonBar;
          import mx.core.ClassFactory;
          import mx.core.mx_internal;
       
          public class CustomButtonBar extends ButtonBar {
              public function CustomButtonBar() {
                  super();
                  mx_internal::navItemFactory = new ClassFactory(CustomButtonBarButton);
              }
          }
      }

      And the custom ButtonBarButton, comps/CustomButtonBarButton.as, is as follows:

      package comps {
          import mx.controls.buttonBarClasses.*;
       
          public class CustomButtonBarButton extends ButtonBarButton {
              public function CustomButtonBarButton() {
                  super();
              }
       
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                  super.updateDisplayList(unscaledWidth, unscaledHeight);
                  super.toolTip = null;
              }
          }
      }

      Peter

    • Peter deHaan says:

      Or, if you want a quicker/cheaper workaround, you could just toggle the ToolTipManager enabled property in a rollOver/rollOut event handler, as seen in the following example:

       
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
       
          <mx:Script>
              <![CDATA[
                  import mx.managers.ToolTipManager;
       
                  protected function bBar_rollOverHandler(evt:MouseEvent):void {
                      ToolTipManager.enabled = false;
                  }
       
                  protected function bBar_rollOutHandler(event:MouseEvent):void {
                      ToolTipManager.enabled = true;
                  }
              ]]>
          </mx:Script>
       
          <mx:ButtonBar id="bBar"
                  width="400"
                  rollOver="bBar_rollOverHandler(event);"
                  rollOut="bBar_rollOutHandler(event);">
              <mx:dataProvider>
                  <mx:ArrayCollection source="[The quick brown fox,Quick brown fox jumps,Brown fox jumps over,Fox jumps over the]" />
              </mx:dataProvider>
          </mx:ButtonBar>
       
          <mx:Button label="The quick brown fox jumps over the" width="100" />
       
      </mx:Application>

      I presume you could also easily extend the ButtonBar class and do this globally for all custom ButtonBar controls.

      Peter

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree