0
我想限制将动画片段拖动到名为“遮罩”的遮罩。可拖动的MC的名字是mapcontainer.themap。它的父母,mapcontainer,与舞台成比例缩放。我如何限制被拖动的MC到面具?下面的代码适用于加载,但不适用于舞台缩放时。限制拖动影片剪辑进行遮罩,使用舞台&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;
}
这不起作用 - 可能是因为可拖动的剪辑的注册点位于中心。有任何想法吗? – lgriffin
是的,所以在这种情况下,您需要对发送给startDrag的矩形进行一些更改,如下所示: –
@ user1342133 var rect:Rectangle = themapmask.getBounds(mapcontainer); mapcontainer.themap.startDrag(false/*或true * /,new Rectangle(rect.left + mapcontainer.themap.width/2,rect.top + mapcontainer.themap.height/2,rect.width - mapcontainer.themap.width ,rect.height - mapcontainer.themap.height))' –