在 Flash CS4 中链接图像/图层 - 让它们一起移动

发布于 2024-08-11 14:52:21 字数 498 浏览 9 评论 0原文

我有两个图像副本(一个称为“blurPic_mc”,一个称为“sharpPic_mc”),并且我希望能够将它们一起在屏幕上移动。对于我正在运行的其他一些功能,我需要它们完全保持在彼此之上,但现在唯一移动的是顶部的功能(sharpPic_mc)。有什么想法吗?我在下面包含了我的代码。

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();
}

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

依 靠 2024-08-18 14:52:21

我相当确定 startDrag 一次只允许拖动一个 MovieClip。所以你会想要这样做。

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文