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();
}
f开发者_开发百科unction Release(event:MouseEvent):void{
event.currentTarget.stopDrag();
blurPic_mc.startDrag();
}
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;
}
精彩评论