前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >AS3的getBounds方法

AS3的getBounds方法

作者头像
py3study
发布2020-01-10 10:31:56
发布2020-01-10 10:31:56
57900
代码可运行
举报
文章被收录于专栏:python3python3
运行总次数:0
代码可运行

1,这个getBound 在某些情况下非常实用.例如,聊天系统的聊天面板.做个这玩意的朋友,应该对着玩意都点熟悉.

2,这里我用这玩意,实现了一个功能: 面板"LevelTitleMainPanel"的关闭策略,除了通过面板上的关闭按钮,还能在此面板的外部单击时,面板也能关闭.

"LevelTitleMainPanel"的部分代码:

代码语言:javascript
代码运行次数:0
运行
复制
override protected function onAddStage():void{
    super.onAddStage();
    listener(true);
}
override protected function onRemoveStage():void{
    super.onRemoveStage();
    listener(false);
}
private function listener( $isAdd : Boolean = true) : void{
    if($isAdd){
        close_btn.addEventListener(MouseEvent.CLICK,__onClickHandler);
        stage.addEventListener(MouseEvent.CLICK,__onxClickHandler);
    }else{
        close_btn.removeEventListener(MouseEvent.CLICK,__onClickHandler);
        stage.removeEventListener(MouseEvent.CLICK,__onxClickHandler);
    }
}
private function __onClickHandler( $e : MouseEvent ) : void{
    this.visible = false;
}
private function __onxClickHandler( $e : MouseEvent ) : void{
    if(!this.visible) return;
    trace("Ainy---LevelTitleMainPanel---事件处理!!!+++");
    var $moX : Number = $e.stageX;
    var $moY : Number = $e.stageY;
    var $round : Rectangle = this.getBounds(stage);
    if($moX < $round.x || $moX > ($round.x + $round.width)){
        this.visible = false;
    }else if($moY > ($round.y + $round.height)){
        this.visible = false;
    }
    trace("StageX:::=>"+$moX+"  StageY:::=>"+$moY);
    trace("Myx:::=>"+$round.x+"  MyY:::=>"+$round);
    trace("MyWidth:::=>"+$round.width+"  MyHeight:::=>"+$round.height);
}

其中"this.getBounds(stage)"表示 LevelTitleMainPanel 在 stage 中的位置及其宽长.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档