CODE:import index.base.func.OutDisplay;
类的源代码:
var menu:Menu = new Menu;
menu.mc1.addEventListener(MouseEvent.MOUSE_OVER,mouseOverFun);
menu.mc2.addEventListener(MouseEvent.MOUSE_OVER,mouseOverFun);
menu.mc3.addEventListener(MouseEvent.MOUSE_OVER,mouseOverFun);
menu.mc4.addEventListener(MouseEvent.MOUSE_OVER,mouseOverFun);
addChild(menu);
function mouseOverFun(e:MouseEvent){
var m:Menu = new Menu;
m.x = e.currentTarget.x e.currentTarget.parent.x;
m.y = e.currentTarget.y e.currentTarget.parent.y;
addChild(m);
var out:OutDisplay = new OutDisplay(MouseEvent.MOUSE_OVER,stage,e.currentTarget);
out.addEventListener(Event.CANCEL,cancelFun);
out.add(m);
m = null;
out = null;
}
function cancelFun(e:Event):void{
var out:OutDisplay = e.currentTarget as OutDisplay;
var tmpAr:Array = out.objects;
removeChild(tmpAr[1]);
out.removeEventListener(Event.CANCEL,cancelFun);
tmpAr = null;
out = null;
}
CODE:package index.base.func{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
import flash.events.EventDispatcher;
public class OutDisplay extends EventDispatcher{
//保存所有对象
private var objAr:Array;
//保存侦听类型
private var type:String;
//保存侦听范围
private var dis:DisplayObject;
//构造函数
public function OutDisplay(_type:String,_dis:DisplayObject,...objs){
type = _type;
objAr = objs;
dis = _dis;
dis.addEventListener(_type,fun);
}
//事件处理
private function fun(e:Event):void{
for(var i:uint = 0;i<objAr.length;i ){
if(e.target == objAr[i]) return;
if(objAr[i] is DisplayObjectContainer){
if(objAr[i].contains(e.target)) return;
}
}
dis.removeEventListener(type,fun);
dispatchEvent(new Event(Event.CANCEL));
}
//添加对象
public function add(...objs):Array{
for(var i:int = 0; i < objs.length; i ){
objAr.push(objs[i]);
}
return objects;
}
//获取对象列表
public function get objects():Array{
return objAr;
}
//卸载
public function clear(isDispatch:Boolean = false):void{
if(isDispatch) dispatchEvent(new Event(Event.CANCEL));
dis.removeEventListener(type,fun);
objAr = null;
}
}
}
IT时代网(关注微信公众号ITtime2000,定时推送,互动有福利惊喜)所有原创文章版权所有,未经授权,转载必究。
创客100创投基金成立于2015年,直通硅谷,专注于TMT领域早期项目投资。LP均来自政府、互联网IT、传媒知名企业和个人。创客100创投基金对IT、通信、互联网、IP等有着自己独特眼光和丰富的资源。决策快、投资快是创客100基金最显著的特点。
小何
小何
小何
小何