views:

272

answers:

1

I have two copies of an image (one called blurPic_mc & one called sharpPic_mc) and I want to be able to move both of them around the screen together. I need them to stay exactly on top of each other for some other functions I am running but right now the only one that moves is the top one (sharpPic_mc). Any Ideas? I included my code below.

sharpPic_mc.addEventListener(MouseEvent.MOUSE_DOWN,Click);
sharpPic_mc.addEventListener(MouseEvent.MOUSE_UP,Release);

function Click(event:MouseEvent):void{
  event.currentTarget.startDrag();
  blurPic_mc.startDrag();
}
function Release(event:MouseEvent):void{
  event.currentTarget.stopDrag();
  blurPic_mc.startDrag();
}
+1  A: 

I am fairly sure startDrag only allows one MovieClip to be dragged at a time. So you will want to do this.

sharpPic_mc.addEventListener(MouseEvent.MOUSE_DOWN,onImageDown); 
blurPic_mc.addEventListener(MouseEvent.MOUSE_DOWN,onImageDown); 


function onImageDown(e:MouseEvent):void
{
  //listening to stage
  stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
  stage.addEventListener(MouseEvent.MOUSE_UP, onImageRelease);
}

function onImageRelease(e:MouseEvent):void
{
  removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
  removeEventListener(MouseEvent.MOUSE_UP, onImageRelease);
}


function onMove(e:MouseEvent):void
{
  blurPic_mc.x = e.stageX;
  blurPic_mc.y = e.stageY;

  sharpPic_mc.x = e.stageX;
  sharpPic_mc.y = e.stageY;
}
Allan
You might wanna consider adding the mouseMove and mouseUp events to the `stage` rather than `this`
Amarghosh
whoops yes I missed that. Edited to fix that.
Allan