return undefined;


Simple monkey patch to fix ToolTipManager.toolTipClass

Posted in AS3, Flex by Ben Clinkinbeard on the July 3rd, 2008

ToolTipManager.toolTipClass doesn't work in Flex 3.0 out of the box. While its intent of allowing you to specify a custom IToolTip implementation is great, ToolTipManagerImpl simply acts as if the property doesn't exist and instantiates an instance of ToolTip. Luckily, the fix is quite easy if you are willing to do a bit of monkey patching. You just have to make a slight modification to the createToolTip() method, making it look like the following:

Actionscript:
  1. public function createToolTip(text:String, x:Number, y:Number,
  2.                                      errorTipBorderStyle:String = null,
  3.                                      context:IUIComponent = null):IToolTip
  4. {
  5.     // ***** USE THE PROPERTY! *****
  6.     var toolTip:IToolTip = new ToolTipManager.toolTipClass();
  7.  
  8.     var sm:ISystemManager = context ?
  9.                             context.systemManager :
  10.                             ApplicationGlobals.application.systemManager;
  11.     sm.toolTipChildren.addChild(UIComponent(toolTip));
  12.  
  13.     if (errorTipBorderStyle)
  14.     {
  15.         UIComponent(toolTip).setStyle("styleName", "errorTip");
  16.         UIComponent(toolTip).setStyle("borderStyle", errorTipBorderStyle);
  17.     }
  18.  
  19.     toolTip.text = text;
  20.  
  21.     sizeTip(toolTip);
  22.  
  23.     toolTip.move(x, y);
  24.     // Ensure that tip is on screen?
  25.     // Should x and y for error tip be tip of pointy border?
  26.  
  27.     // show effect?
  28.  
  29.     return toolTip;
  30. }

Here is a diff of the base and updated classes.

As an aside, an easier fix is said to exist here, but it doesn't seem to work when calling ToolTipManager.createToolTip() directly, which is what I needed to do. If you are using toolTips normally by just setting the toolTip property I would recommend trying Peter's fix first.

I would also like to go on record that I hate the *Impl naming convention. Despite what Theo says, I like my interfaces with I's. *Impl just seems kludgy and redundant, and it reminds me of AS2.

3 Responses to 'Simple monkey patch to fix ToolTipManager.toolTipClass'

Subscribe to comments with RSS or TrackBack to 'Simple monkey patch to fix ToolTipManager.toolTipClass'.

  1. Rick Winscot said,

    on July 3rd, 2008 at 5:11 pm

    If I remember correctly - this 'bug' was marked deferred with a workaround. Workaround as in... if the bug sits long enough Ben will probably get sick of futzing with it and throwdown a monkey patch. Thanks for the bits Ben.

  2. Morten said,

    on August 28th, 2008 at 3:25 pm

    I have just the same problem. I wan't to use cutom tooltip with the "createTooltip" method.
    I've tried patching my eclipse flex with the latest 3.1SDK all afternoon and evening - but to no avail! Either the patching doesn't work (which i think might be the most probable thing) - or the patch does not live well with 3.1?

    Can you go into a BIT more detail on how you actually do the patching (ie: create a "stub" SWC to include etc.) To me, it seems that, whatever I do, it's the original flex sdk that gets called by my app.... arrrg

    regards
    Morten


  3. on August 28th, 2008 at 3:51 pm

    Hi Morten,

    You don't actually need to create a whole new SWC. To monkeypatch a class in Flex all you do is copy the class from the framework and save it in your project under the same package it came from. So in your project you would create mx.managers.ToolTipManager or whatever it is, copy in the code from the framework and then edit whatever it is you need. When your project is compiled it will use your local class instead of the one in the framework.

    If thats not clear hit up Google, I am sure there is more info out there about monkeypatching Flex.

    HTH,
    Ben

Leave a Reply