首页 文章

Actionscript 3中的双拖动功能

提问于
浏览
0

我有两个动画片段,一个动画片段垂直拖动,另一个拖动水平 . 如果我滑动水平动画片段,我希望垂直动画片段也可以垂直拖动(如菜单) . 我通过在一个拖动功能中放置两个拖动功能来尝试这个,但它没有用 . 任何人都可以帮我吗?

menu0.bar1.thumbnail1.addEventListener(MouseEvent.MOUSE_DOWN, startdrag1)
stage.addEventListener(MouseEvent.MOUSE_UP, stopdrag1)

function startdrag1 (e:MouseEvent)
{
    menu0.addEventListener(MouseEvent.MOUSE_DOWN, startdrag)
    menu0.removeEventListener(MouseEvent.MOUSE_DOWN, startdrag)

    //Horizontal dragging menu
    menu0.bar1.thumbnail1.startDrag(false, new Rectangle(0,125,-1380,0));

    //Vertical dragging menu
    menu0.startDrag(false,new Rectangle(0,93,0,-1125));

}
function stopdrag1 (e:MouseEvent)
{
    menu0.bar1.thumbnail1.stopDrag();
    menu0.addEventListener(MouseEvent.MOUSE_DOWN, startdrag)
    menu0.bar1.stopDrag();
}

它只会水平拖动,但菜单不会拖动 . (缩略图在菜单中,脚本在其外部)

1 回答

  • 1

    你应该重写一个拖拽功能,这不是很痛苦 . 我真的不明白你的符号,所以让我们假设我们有两个片段:

    var verticalClip:Sprite = new Sprite();
    var horizontalClip:Sprite = new Sprite();
    

    当第二个被水平拖动时,您希望第一个垂直移动 .

    horizontalClip.addEventListener(MouseEvent.MOUSE_DOWN, hMouseDown);
    
    private function hMouseDown(e:MouseEvent):void
    {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, hMouseMove);
        stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
    }
    
    private function hMouseMove(e:MouseEvent):void
    {
        horizontalClip.x = stage.mouseX;
        verticalClip.y = stage.mouseX; //you may want to add some limits and offsets here
    }
    
    private function stageMouseUp(e:MouseEvent):void
    {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, hMouseMove);
    }
    

    如果您希望verticalClip也可以拖动,您仍然可以使用startdrag . 或者,如果您需要一些更复杂的行为(例如在拖动verticalClip时移动horizontalClip),只需模仿以前的代码即可 .

相关问题