美文网首页
Layabox:点击tip框外面的位置关闭tip框

Layabox:点击tip框外面的位置关闭tip框

作者: 一眼就认出你 | 来源:发表于2020-12-15 14:24 被阅读0次

    语言:LayaBox - AS3

    效果图.png
    示例:
    第一步:鼠标点击事件的监听函数绑定给了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
    }
    

    相关文章

      网友评论

          本文标题:Layabox:点击tip框外面的位置关闭tip框

          本文链接:https://www.haomeiwen.com/subject/ytbtohtx.html