我想把电影剪辑的拖拽限制在一个叫做themapmask的遮罩上。可拖动的mc的名称是mapcontainer.themap。它的父级mapcontainer与stage成比例缩放。如何将拖拽的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;
}发布于 2012-09-28 08:40:33
Sprite.startDrag函数接受第二个参数,特别是对于拖动区域约束,而DisplayObject.getBounds函数在参数DisplayObject的上下文中返回一个矩形,其中包含应用到的对象的边界。所以,基本上,你需要做的是:
mapcontainer.themap.startDrag(false /*or true*/, themapmask.getBounds(mapcontainer));而且你可以完全放弃整个constrainMap函数。
https://stackoverflow.com/questions/12631692
复制相似问题