如何在Flex中的某些行之前拖动和停止面板?

时间:2013-04-16 12:13:23

标签: flex draggable panel drag

我正在尝试拖动我的面板并在某条线之前停止我的面板。我不知道该怎么做。 让我用我的代码解释(它不起作用):

//MyPanel
<s:Panel                                                                         
  mouseMove="rectangle_mouseMoveHandler(event)"
  width="30" height="30" id="panel" backgroundAlpha="0.2" 
  mouseDown="onMouseDown(event)" mouseUp="onMouseUp(event)"                              
  skinClass="intetech.PanelNoTitleBar" backgroundColor="blue">                                                      
</s:Panel>


//rectangle_mouseMoveHandler
protected function rectangle_mouseMoveHandler(event:MouseEvent):void
    {

        if ((panel.x+panel.width)>=(minimap.x+minimap.width)){
            panel.x = (minimap.x+minimap.width-panel.width+0.001);              
        }
        trace("panel.x = "+panel.x);
    }

1 个答案:

答案 0 :(得分:1)

您可以使用相对于Sprite父级坐标的边界来指定Sprite的约束矩形:

protected function panel_mouseUpHandler(event:MouseEvent):void
{
    panel.stopDrag();
}

protected function panel_mouseDownHandler(event:MouseEvent):void
{
    panel.startDrag(false, new Rectangle( 0,0, 500, 300));
}

//...

<s:Panel id="panel" width="300" height="200" mouseUp="panel_mouseUpHandler(event)" mouseDown="panel_mouseDownHandler(event)"/>