2015-09-07 103 views
0

上午有我的视频播放器两个控件选择开始点和结束点,请参考附件图片如何在AS3中为可拖动对象定义动态边界?

enter image description here 这些contorls的名称分别是inpoint_mcscrub_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只有dragable直到它到达scrub_outpoint_mc,并scrub_outpoint_mc只有dragable直到它到达inpoint_mc

回答

1

您需要根据其他擦洗点的位置来计算拖动矩形。您的矩形现在包含progressBar_mc下的区域,现在您必须根据inpoint_mcscrub_outpoint_mc的位置对其进行修剪。为此,您需要更改用于限制startDrag()的矩形的xwidth

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); 

    } 
+0

你是天才。它运作良好:) –

+0

Vesper,是否可以用任何颜色填充矩形? –

+0

那么,这是值得的另一个问题,有足够的细节,你想在哪里放置一个彩色的矩形,等等。总之,是的,但实施会有所不同。 – Vesper