Reputation: 3
I have two movieclips, one movieclip drags vertical, the other one drags horizontal. If I slide the horizontal movieclip, I want the vertical movieclip to drag vertical aswell (like a menu). I have tried this by putting two drag functions in one drag function, but it didn't work. Could anyone help me out?
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();
}
It will only drag horizontal, but the menu won't drag. (The thumbnail is in the menu, and the script is outside it all)
Upvotes: 0
Views: 191
Reputation: 5978
You should rewrite a drag function, it's not really painful. I don't really understand your notations, so let's suppose we have two clips:
var verticalClip:Sprite = new Sprite();
var horizontalClip:Sprite = new Sprite();
You want the first one to move verticaly when the second one is dragged horizontaly.
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);
}
If you want the verticalClip to be draggable as well, you can still use startdrag. Or if you need some more complex behaviour (such as moving the horizontalClip when dragging the verticalClip), just mimic the previous code.
Upvotes: 1