AS3的getBounds方法

发布时间:2019-08-28 09:06:39编辑:auto阅读(1838)

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

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

    "LevelTitleMainPanel"的部分代码:

    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 中的位置及其宽长.


关键字

上一篇: saltstack (3) grains

下一篇: 1.1.1 The Python Int