0

我想将影片剪辑的拖动限制在名为 themapmask 的蒙版上。可拖动 mc 的名称是 mapcontainer.themap。它的父级 mapcontainer 与舞台成比例地缩放。如何将拖动的 mc 约束到蒙版?下面的代码在加载时有效,但在舞台缩放时无效。

function constrainMap():void {
    leftedge = themapmask.x+mapcontainer.themap.width/2-mapcontainer.x;
    rightedge= themapmask.x+themapmask.width-mapcontainer.width/2-mapcontainer.x;
    topedge = themapmask.y+mapcontainer.themap.height/2-mapcontainer.y;
    bottomedge = themapmask.y+themapmask.height-mapcontainer.height/2-mapcontainer.y;
    if (mapcontainer.themap.x>leftedge) mapcontainer.themap.x=leftedge;
    if (mapcontainer.themap.y>topedge) mapcontainer.themap.y=topedge;
    if (mapcontainer.themap.x<rightedge) mapcontainer.themap.x=rightedge;
    if (mapcontainer.themap.y<bottomedge) mapcontainer.themap.y=bottomedge;
}
4

1 回答 1

1

Sprite.startDrag函数接受第二参数,特别是对于拖动区域约束,DisplayObject.getBounds函数返回一个矩形,该矩形具有参数 DisplayObject 上下文中应用对象的边界。所以,基本上,你需要做的是:

mapcontainer.themap.startDrag(false /*or true*/, themapmask.getBounds(mapcontainer));

你可以完全放弃整个constrainMap函数。

于 2012-09-28T00:40:33.267 回答