语言:LayaBox - AS3
示例:
第一步:鼠标点击事件的监听函数绑定给了canvas(舞台)
第二步:
public static function checkItemUseDlg(target:*):void{
//获取tip所在的页面(tip挂载的父级页面)
var dlg:* = GameUIManager.instance.getUI(1);
//判断是否点击tip框以外的位置
if(dlg && dlg.visible && Tools.isAncestor(target,dlg)){
dlg.hide()
}
}
判断点击的目标不是tip框的代码
public static function isAncestor(curWindow:Sprite,ancestor:Sprite):Boolean{
var flag:Boolean = curWindow == ancestor
if(!flag){
var parentNode:Sprite = curWindow.parent as Sprite
while(parentNode){
flag = parentNode == ancestor
if(flag)
break
parentNode = parentNode.parent as Sprite
}
}
return flag
}