如何在AS3中为可拖动对象定义动态边界?

时间:2015-09-07 08:24:45

标签: actionscript-3 flash

我的视频播放器上有两个控件可供选择起点和终点,请参阅附图

enter image description here 这些控件的名称分别是 inpoint_mc scrub_outpoint_mc ,我添加了监听器函数来为两个控件拖动自身

this.controls_mc.inpoint_mc.addEventListener(MouseEvent.MOUSE_DOWN, this.startScrubbingIN);
            this.controls_mc.scrub_outpoint_mc.addEventListener(MouseEvent.MOUSE_DOWN, this.startScrubbingOUT);

private function startScrubbingIN(_arg1:MouseEvent){
            trace("scrubBarIsMovingIN");
            this.cueCard.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScrubbingIN);
            this.cueCard.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.scrubBarIsMovingIN);
            this.scrubbing = true;
            var _local2:Rectangle = new Rectangle(this.controls_mc.progressBar_mc.x, this.controls_mc.inpoint_mc.y, this.controls_mc.progressBar_mc.width, 0);
            this.controls_mc.inpoint_mc.startDrag(false, _local2);

        }

        private function startScrubbingOUT(_arg1:MouseEvent){
            this.cueCard.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScrubbingOUT);
            this.cueCard.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.scrubBarIsMovingOUT);
            this.scrubbing = true;
            var _local2:Rectangle = new Rectangle(this.controls_mc.progressBar_mc.x, this.controls_mc.scrub_outpoint_mc.y, this.controls_mc.progressBar_mc.width, 0);
            this.controls_mc.scrub_outpoint_mc.startDrag(false, _local2);

        }

我的目标是,我不希望它们彼此超越,意味着 inpoint_mc 只能拖动才能达到 scrub_outpoint_mc ,并且 scrub_outpoint_mc 只有在达到 inpoint_mc

时才可拖动

1 个答案:

答案 0 :(得分:1)

您需要根据其他磨砂点的位置计算拖动矩形。您的矩形现在包含progressBar_mc下的区域,现在您必须根据inpoint_mcscrub_outpoint_mc的位置修剪它。为此,您需要更改用于限制x的矩形的widthstartDrag()

    private function startScrubbingIN(_arg1:MouseEvent){
        trace("scrubBarIsMovingIN");
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScrubbingIN);
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.scrubBarIsMovingIN);
        this.scrubbing = true;
        var _local2:Rectangle = new Rectangle(this.controls_mc.progressBar_mc.x, this.controls_mc.inpoint_mc.y, 
            this.controls_mc.scrub_outpoint_mc.x-this.controls_mc.progressBar_mc.x, 0);
        // now we're limiting in point to current position of out point
        this.controls_mc.inpoint_mc.startDrag(false, _local2);

    }

    private function startScrubbingOUT(_arg1:MouseEvent){
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScrubbingOUT);
        this.cueCard.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.scrubBarIsMovingOUT);
        this.scrubbing = true;
        var _local2:Rectangle = new Rectangle(this.controls_mc.inpoint_mc.x, this.controls_mc.scrub_outpoint_mc.y, 
            this.controls_mc.progressBar_mc.width+this.controls_mc.progressBar_mc.x-this.controls_mc.inpoint_mc.x, 0);
        // the same for out, but the width of the rectangle is calculated to include x offset
        this.controls_mc.scrub_outpoint_mc.startDrag(false, _local2);

    }
相关问题