zoukankan      html  css  js  c++  java
  • 鼠标经过延时出现Hint

    舞台上有个影片剪辑mc
    库中有个元件hint由bg元件和文本txt组成
    import flash.events.MouseEvent;
    
    var time:int = 500;
    var dyid:int;
    var flag:Boolean;
    
    mc.addEventListener(MouseEvent.ROLL_OVER,_onRollOver);
    mc.addEventListener(MouseEvent.ROLL_OUT,_onRollOut);
    
    function _onRollOver(e:MouseEvent):void
    {
    	dyid = setTimeout(delayed,time,e);
    }
    function delayed(e:MouseEvent):void
    {
    	flag = true;
    	Hint.addHint(e,"延时"+time+"毫秒");
    }
    function _onRollOut(e:MouseEvent):void
    {
    	if (flag)
    	{
    		flag = false;
    		Hint.removeHint();
    	}
    	clearTimeout(dyid);
    }
    
    package
    {
    	import flash.display.DisplayObject;
    	import flash.display.MovieClip;
    	import flash.display.Sprite;
    	import flash.display.Stage;
    	import flash.events.MouseEvent;
    	import flash.geom.Rectangle;
    	import flash.text.TextField;
    	import flash.text.TextFieldAutoSize;
    
    	public class Hint extends Sprite
    	{
    		private static  var _txt:TextField;
    		private static var _mcBg:MovieClip;
    		private static var _hint:Hint;
    		private static var _stage:Stage;
    		public function Hint() 
    		{
    			_txt = getChildByName("txt") as TextField;
    			_mcBg = getChildByName("bg") as MovieClip;
    		}
    		public static function getInstance():Hint
    		{
    			if (_hint == null)
    			{
    				_hint = new Hint();
    			}
    			return _hint;
    		}
    		public static function addHint(e:MouseEvent,str:String):void
    		{
    			_stage = e.target.stage;
    			_stage.addChild(getInstance());	
    			_txt.text = str;
    			_txt.autoSize = TextFieldAutoSize.CENTER;
    			resize();
    			getInstance().x = _stage.mouseX;
    			getInstance().y = _stage.mouseY;
    			_stage.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
    		}
    		public static function moveHandler(e:MouseEvent):void
    		{
    			getInstance().x = _stage.mouseX;
    			getInstance().y = _stage.mouseY;
    		}
    		public static function resize():void
    		{
    			_mcBg.width = _txt.textWidth + 30;
    		}
    		public static function removeHint():void
    		{
    			_stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
    			_stage.removeChild(getInstance());
    		}
    	}
    
    }
    
  • 相关阅读:
    1.Http讲解
    1.创建SpringMVC项目
    0.学习springmvc补充
    apache-maven安装
    apache-tomcat安装
    Tomcat启动问题:严重[main] org.apache.catalina.core.AprLifecycleListener.init An incompatible version...
    Tomcat启动服务报错:Unknown version string [4.0]. Default version will be used.
    设置make为内部命令
    Xshell6和Xftp6初步使用
    Swift字符串类型
  • 原文地址:https://www.cnblogs.com/602147629/p/1942972.html
Copyright © 2011-2022 走看看