flex 1.0 中显示树的微帮助

调用方法
  dsgToolTip.showtreeToolTip=true; //是否显示
  dsgToolTip.treeid=["mytree1"];
//显示的数组,值是树的id


as文件

import mx.utils.Delegate;
import mx.managers.ToolTipManager;
import mx.managers.DepthManager;
import mx.events.LowLevelEvents

/**
 *用于树显示微提示
 */

class dsgToolTip
{

 /**
  * @private
  * Internal property for monitoring getter/setter.
  *
  * @see #get monitoring
  * @see #set monitoring
  */
 private static var __monitoring:Boolean = false;

 private static var __showtreeid:Array;

 private static var __showid:Array ;
 static function set treeid(st:Array)
 {
  __showtreeid=st;
 }

 /**
  * Check the current monitoring status of this spy.
  *
  * @return true for monitoring enabled, false for disabled.
  */ 
 static function get treeid():Array
 {
  return __showtreeid;
 }
 
 /**
  * @private
  * Cached property for the latest detected
  * MovieClip/TextField under the cursor/setter.
  *
  */
 private static var __oldDetected;


 /**
  * @private
  * A object receive and process the global key events.
  *
  * @see #handleKeyDownSomewhere
  */
 private static var __globalKeyDownProxy:Object;


 /**
  * @private
  * Press this key to show more info of the detected
  * MovieClip/TextField .
  *
  * @see #handleKeyDownSomewhere
  */

 /**
  * @private
  * The spy canvas.
  *
  * @see #drawToolTip
  */
 private static var __spyCanvas:MovieClip;
 private static var __spyCanvasDepth:Number=DepthManager.reservedDepth-1;

 

 static var MovieClipProperties:Array=new Array("text");
 

 


 static var defaultToolTipProvider:Function=pathToolTipProvider;


 
 /**
  * @private
  * Set up canvas and event responses
  *
  */
 private static function initializeHandler():Void
 {
  __spyCanvas=_root.createEmptyMovieClip("__spyCanvas", __spyCanvasDepth);
  __spyCanvas.toolTipClass = "mx.controls.ToolTip";
  LowLevelEvents.addUndetectableMovieClip(__spyCanvas);
  
  ToolTipManager.addEventListener("mouseChangeSomewhere",Delegate.create(dsgToolTip,dsgToolTip.handleMouseChangeSomewhere));
  ToolTipManager.addEventListener("mouseDownSomewhere",Delegate.create(dsgToolTip,dsgToolTip.handleMouseDownSomewhere));

 }


 /**
  * Enable/Disable monitoring of MovieClip/TextField.
  *
  * @param b true for enable monitoring, false for disable.
  */
 static function set showtreeToolTip(b:Boolean)
 {
  __monitoring=b;
 }


 /**
  * Check the current monitoring status of this spy.
  *
  * @return true for monitoring enabled, false for disabled.
  */ 
 static function get showtreeToolTip():Boolean
 {
  return __monitoring;
 }


 /**
  * Show spy info(highlight and tooltip) on the specified MovieClip or TextField
  *
  * @param mcOrTf the MovieClip or TextField.
  * @param tooltipProvider a function which return a string,
  * FlexSpy use this string as the tooltip. If no tooltipProvider is specified,
  * the default pathToolTipProvider will be used.
  * @param highlightProvider a function which draw something on the canvas.
  * FlexSpy use this function draws highlight on the spyCanvas. If no highlightProvider
  * is specified, the default redRectangleHighlightProvider will be used.
  * @see #pathToolTipProvider
  * @see #redRectangleHighlightProvider
  */
 static function spy(mcOrTf,tooltipProvider:Function,highlightProvider:Function):Void
 {
  clear();
  if(tooltipProvider==undefined)
  {
   tooltipProvider=defaultToolTipProvider;
  }
  drawToolTip(tooltipProvider(mcOrTf));

  __oldDetected=mcOrTf;
 }

 

 /**
  * Clear previous spy info(highlight and tooltip)
  */
 static function clear():Void
 {
  clearToolTip();
 }
 

 


 /**
  * @private
  * A tooltipProvider(default), this function returns the _target
  * property string of the input MovieClip or TextField.
  *
  * @param mcOrTf the MovieClip or TextField.
  * @return the target path
  */
 private static function pathToolTipProvider(mcOrTf):String
 {
  var tmp :String="";
  var tmpname :String =String(mcOrTf.styleName);
  var  i :Number = tmpname.lastIndexOf(".");
  tmpname = tmpname.substr(i+1,tmpname.length-i);   
  if ((searchArray(__showtreeid,tmpname) != null )&&( mcOrTf.type =="dynamic") && (mcOrTf.text!=" "))
  {
   tmp = mcOrTf.text; 
  } 
  return tmp;
 }


 private static  function searchArray(whichArray,searchElement)
 {
  for (var i=0;i<whichArray.length;i++)
  {
   if (whichArray[i] == searchElement)
   {
    return i;
   }
  }
  return null;
 }

 /**
  * @private
  * Draw the tooltip on the spyCanvas
  *
  * @param tip the tooltip string.
  */
 private static function drawToolTip(tip:String):Void
 {
  __spyCanvas.toolTip=tip;
  ToolTipManager.currentTarget=__spyCanvas;
  ToolTipManager.createAndShowTip();
 }

 /**
  * @private
  * Clear the tooltip on the spyCanvas
  *
  */
 private static function clearToolTip():Void
 {
  __spyCanvas.toolTip=undefined;
  ToolTipManager.currentTarget=undefined;
  ToolTipManager.hideAndDestroyTip();
 }

 /**
  * @private
  * Detect the MovieClip/TextField which under the cursor,
  * and show the spy info(highlight and tooltip) on it.
  *
  * @param eventObj the 'mouseChangeSomewhere' event object.
  */
 private static function handleMouseChangeSomewhere(eventObj:Object):Void
 {
  var newDetected=eventObj.relatedTarget;
  if(__monitoring)
  {
   if(newDetected!=undefined)
   {
    if(newDetected!=__oldDetected)
    {
     spy(newDetected);
    }
   }
   else
   {
    clear();
    __oldDetected=undefined;
   }
  }
 }

 /**
  * @private
  * Clear the previous spy info when mouse is down.
  *
  * @param eventObj the 'mouseDownSomewhere' event object.
 */
 private static function handleMouseDownSomewhere(eventObj:Object)
 {
  if(__monitoring)
  {
   clear();
  }
 }
 


 /**
  * @private
  * Static construct.
  *
  */
 private static function classConstruct():Void
 {
  if(classConstructed)
  {
   return
  }

  initializeHandler();

  clearInterval(classConstructID);
  classConstructed=true;
 }
 
 private static var classConstructed:Boolean=false;
 private static var classConstructID:Number=setInterval(classConstruct,1);

 private static var ToolTipManagerDependency:Function=mx.managers.ToolTipManager; 
 private static var DepthManagerDependency:Function=mx.managers.DepthManager;
 private static var LowLevelEventsDependency:Function=mx.events.LowLevelEvents;
 private static var DelegateDependency:Function=mx.utils.Delegate;

}


效果显示

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值