Monday, March 3, 2008

How to set a custom ToolTipManager

I needed to set a custom implementation of the ToolTipManager (more struts for our life!!!). I was looking for solution and found it. Here it is.

To register your own class you should invoke Singleton.registerClass(interfaceName, clazz) method with appropriate parameters. If class with interfaceName have been registered yet you cannot override it . It means you cannot register class in creationComplete, initialize or preinitialize handlers. You should create custom Preloader class and register class in constructor and set one to the application class via MXML code:


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preloader="CustomPreloader">



Here is the example of custom preloader class:


public class CustomPreloader extends DownloadProgressBar
{
public function CustomPreloader()
{
super();
Singleton.registerClass("mx.managers::IToolTipManager2",
CustomToolTipManager);
}

}



Maybe anyone has another solution.

5 comments:

Abdul Areef said...

i would like to know that, how to integrate the flex with struts. if you have any idea means, please share with me.


my mail id - areef@visiontss.com

Unknown said...

not that Singleton requires your class to have 'getInstance' method.

Here's an example of a custom ToolTipManagerImpl class which disables the error tooltips:

public class CustomToolTipManagerImpl extends ToolTipManagerImpl
{
private static var instance:IToolTipManager2;

public static function getInstance():IToolTipManager2
{
if (!instance)
instance = new CustomToolTipManagerImpl();

return instance;
}

public override function registerErrorString(target:DisplayObject, oldErrorString:String, newErrorString:String):void
{
// do nothing - don't show tooltip
}

public function CustomToolTipManagerImpl()
{
super();
}
}

Unknown said...

not that Singleton requires your class to have 'getInstance' method.

Here's an example of a custom ToolTipManagerImpl class which disables the error tooltips:

public class CustomToolTipManagerImpl extends ToolTipManagerImpl
{
private static var instance:IToolTipManager2;

public static function getInstance():IToolTipManager2
{
if (!instance)
instance = new CustomToolTipManagerImpl();

return instance;
}

public override function registerErrorString(target:DisplayObject, oldErrorString:String, newErrorString:String):void
{
// do nothing - don't show tooltip
}

public function CustomToolTipManagerImpl()
{
super();
}
}

Anonymous said...

You've just saved my life, thanks a lot.

Anonymous said...
This comment has been removed by the author.