在 HDividedBox 中一次移动多个分隔线

发布于 2024-08-25 23:36:56 字数 1869 浏览 8 评论 0原文

我正在尝试在图表下方显示一个带有可拖动视口的小地图。我基本上用它来控制图表的视口:

<mx:annotationElements>
 <mx:HDividedBox id="dividedBox" horizontalScrollPolicy="off" width="100%" height="100%" liveDragging="true" borderSides="bottom top">
     <mx:Canvas id="leftBox" backgroundColor="#FFFFFF" backgroundAlpha="0.5" width="50%" height="100%" borderColor="#333333" borderThickness="1" borderStyle="solid" borderSides="top right bottom" />
     <mx:Canvas id="centerBox" backgroundColor="#FFFFFF" backgroundAlpha="0" width="50%" height="100%" buttonMode="true" minWidth="100" mouseDown="rangeWindowMouseHandler(event);" mouseUp="rangeWindowMouseHandler(event);" mouseMove="rangeWindowMouseHandler(event);" />
     <mx:Canvas id="rightBox" backgroundColor="#FFFFFF" backgroundAlpha="0.5" width="0%" height="100%" borderColor="#333333" borderThickness="1" borderStyle="solid" borderSides="top left bottom" />
  </mx:HDividedBox>
</mx:annotationElements>

使用以下脚本:

private function rangeWindowMouseHandler(event:MouseEvent):void { 
    if(event.target === centerBox) {  
     var coords:Object = rangeDragCoordinates; 

     switch(event.type.toLowerCase()) {
      case 'mousedown':
       rangeDrag = true;
       break;
      case 'mouseup':
       rangeDrag = false;       
       break;
      case 'mousemove':           
       if(rangeDrag) {        
        var xDiff:Number = -(coords.x - event.stageX) * 4.0;

        for(var i:Number = 0; i < dividedBox.numDividers; i++) {         
         dividedBox.moveDivider(i, xDiff);
        }  

       }
       break;
     }

     coords.x = event.stageX;
     coords.y = event.stageY;
    }
   } 

问题是,一次只有一个分隔线实际移动。我发现如果我在移动下一个分隔线之前设置大约 50 毫秒的超时,那么两个分隔线都会移动。然而,这似乎是一种相当尴尬的方法,而且很容易出错。

有人知道是否可以同时移动 HDividedBox 中的两个分隔板,还是我应该采取另一种方法?

I'm trying to have a minimap display with a draggable viewport below a chart. I essentially have this to control the viewport of the chart:

<mx:annotationElements>
 <mx:HDividedBox id="dividedBox" horizontalScrollPolicy="off" width="100%" height="100%" liveDragging="true" borderSides="bottom top">
     <mx:Canvas id="leftBox" backgroundColor="#FFFFFF" backgroundAlpha="0.5" width="50%" height="100%" borderColor="#333333" borderThickness="1" borderStyle="solid" borderSides="top right bottom" />
     <mx:Canvas id="centerBox" backgroundColor="#FFFFFF" backgroundAlpha="0" width="50%" height="100%" buttonMode="true" minWidth="100" mouseDown="rangeWindowMouseHandler(event);" mouseUp="rangeWindowMouseHandler(event);" mouseMove="rangeWindowMouseHandler(event);" />
     <mx:Canvas id="rightBox" backgroundColor="#FFFFFF" backgroundAlpha="0.5" width="0%" height="100%" borderColor="#333333" borderThickness="1" borderStyle="solid" borderSides="top left bottom" />
  </mx:HDividedBox>
</mx:annotationElements>

With the following script:

private function rangeWindowMouseHandler(event:MouseEvent):void { 
    if(event.target === centerBox) {  
     var coords:Object = rangeDragCoordinates; 

     switch(event.type.toLowerCase()) {
      case 'mousedown':
       rangeDrag = true;
       break;
      case 'mouseup':
       rangeDrag = false;       
       break;
      case 'mousemove':           
       if(rangeDrag) {        
        var xDiff:Number = -(coords.x - event.stageX) * 4.0;

        for(var i:Number = 0; i < dividedBox.numDividers; i++) {         
         dividedBox.moveDivider(i, xDiff);
        }  

       }
       break;
     }

     coords.x = event.stageX;
     coords.y = event.stageY;
    }
   } 

Problem is, only one divider actually moves at a time. I found that if I set a timeout of about 50ms before moving the next divider that both dividers move. However, this seems like a rather awkward way to approach this and is error prone.

Anyone know if it's possible to move two dividers in a HDividedBox simultaneously or should I be taking another approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2024-09-01 23:36:56

最终需要使用 callLater 调用其他分隔符上的更新,而不是立即调用它。

Ended up needing to call the updates on the other divider(s) using callLater rather than calling it immediately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文