Cannot figure this one out. How do i constrain the drag of an mc whose registration point is in the center to a larger clip whose registration point is also in the center? The code below drags the clip named img, but doesn’t constrain to the ‘rect’ clip.
var bounds:Rectangle = new Rectangle(rect.width/2-img.width/2, rect.height/2-img.height/2, rect.width-img.width, rect.height-img.height);
img.addEventListener(MouseEvent.MOUSE_DOWN, drag);
img.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(event:MouseEvent) {
img.startDrag(false, bounds);
}
function drop(event:MouseEvent) {
img.stopDrag();
}
If
rectis the rectangle you want your object (img) to stay inside of, and they are both anchored in the center, then this is what you need: