A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: A simple tooltip function that can be easily changed!

  1. #1
    Unaffiliated deity.
    Join Date
    Sep 2000
    Tallahassee, FL

    A simple tooltip function that can be easily changed!

    After messing with virtually every componentized tooltip under the sun and discovering that NONE of them can redraw a new message if the tooltip data changes, I decided to throw together something very simple that can be called from anywhere and always works. I'm calling it the "bTooltip" because my name is Brett and I'm sick of tooltips that don't work right and come with zero documentation. I hope this simple function saves someone a weekend, of trying to programatically change one of those crappy tooltip components from the Macromedia/Adobe Exchange. This one isn't feature-rich, but it should be easy for anyone to tweak if they wan't other features. Also, if someone wants to fix this to show the correct fonts, feel free.

    // Simply put this function on your _root timeline and then call it from
    // anywhere by using _root.bTooltip("message text", true);
    // I just attach it to the onRollOver event of buttons and movieclips. 
    // The first parameter is the message to display. The second parameter
    // can either be a width to display a fixed width tooltip with wordwrapping, 
    // or you can pass a boolean "true" or string "autosize" to have it size
    // itself to the raw string. If you use autosize option you have to put
    // your own linebreaks in the string using "\n" characters. 
    // To hide/destroy a tooltip simply call the function with false like this:
    // _root.bTooltip(false,false); 
    // Just attach this to the onRollOut event of a button or movieclip
    function bTooltip(message_string,the_width){
    	var autosizeit = false;
    		_global.tooltip_depth = _root.getNextHighestDepth();
    	//unload the tooltip if we called the function with "false"
    	//let's be redundant since flash is a memory leaking whore
    	if(message_string == false){
    		delete _root.tooltip;
    	//create the tooltip
    	_root.tooltip._visible = false;
    	if(message_string == "" || message_string == undefined){
    		message_string = "You did not set your message properly. This text is displaying for diagnistic purposes so that you can see if the word wrapping and other features are working right";
    	if(the_width == "autosize" || the_width == true){
    		the_width = 20;
    		autosizeit = true;
    	_root.tooltip.text_field.font = "_sans";
    	if(autosizeit == true){
    		_root.tooltip.text_field.autoSize = "left";
    		_root.tooltip.text_field.autoSize = "left";
    	_root.tooltip.text_field.type = "dynamic";
    	_root.tooltip.text_field.border = false;
    	_root.tooltip.text_field.multiline = true;
    	_root.tooltip.text_field.html = true;
    	_root.tooltip.text_field.embedFonts = false;
    	_root.tooltip.text_field.selectable = false;
    	if(autosizeit == true){
    		_root.tooltip.text_field.wordWrap = false;
    		_root.tooltip.text_field.wordWrap = true;
    	_root.tooltip.text_field.mouseWheelEnabled = false;
    	//text_field.condenseWhite = false;
    	//text_field.styleSheet = undefined;
    	_root.tooltip.text_field.text = message_string;
    	//now draw the background and outline
    	_root.tooltip.beginFill(0xFFFF99, 80);
    	_root.tooltip.lineStyle(1, 0x000000, 80);
    	_root.tooltip.moveTo(0, 0);
    	_root.tooltip.lineTo(_root.tooltip.text_field._width, 0);
    	_root.tooltip.lineTo(_root.tooltip.text_field._width, _root.tooltip.text_field._height);
    	_root.tooltip.lineTo(0, _root.tooltip.text_field._height);
    	_root.tooltip.onEnterFrame = function(){
    		if(this._visible == false){
    			this._visible = true;
    		this._x = _xmouse + 15;
    		this._y = _ymouse + 5;
    Note: Originally I used a "with(_root.tooltip)" statement to set all the tooltip and text_field properties, but discovered that this screwed up the scope of the variables I was passing into the function to control the sizing, so I switched it back to the long way.
    Last edited by minorgod; 09-11-2006 at 11:08 PM.
    Nowhere does science promise emancipation.

  2. #2
    Senior Member
    Join Date
    May 2004
    Found this and it's excellent! Thanks for that!!!
    Everybody has a story to tell, what's yours? -- http://www.filmfiler.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center