AS3 - Constrain startDrag movement to mask

Hi

I have a small movieclip where an external image gets loaded into a custom shape mask. The user can then drag the image around. This is all working fine.

I am now trying to constrain the movement allowed so that the image cannot ever leave the masked area.

On my startDrag() function i have tried to include the following properties but i cannot get this to work:

(false,new Rectangle(-xpos,ypos,stage.stageWidth,0));

Full code is pasted below and fla file attached. Any help would be extremely grateful.


// Imports.
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
//

// Load External Image into loader.
var imageP1:Loader = new Loader();
var request:URLRequest=new URLRequest("http://www.tiltworld.co.uk/TH785RFD/image.jpg");
imageP1.load(request);
addChild(imageP1);
imageP1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
var imageA1:Bitmap;

function onLoadComplete(event:Event):void {
	imageA1=new Bitmap(Bitmap(imageP1.content).bitmapData.clone());
	imageA1.alpha=0;
	imageP1.x=imageA1.x=67;
	imageP1.y=imageA1.y=67;
	imageP1.width=imageA1.width=425;
	imageP1.height=imageA1.height=282;
	imageA1_Content.addChild(imageA1);
	imageP1.mask=maskP1;
}
//

// Make Loader a Child of Sprite.
var image_Content:Sprite = new Sprite();
var imageP1_Content:Sprite = new Sprite();
var imageA1_Content:Sprite = new Sprite();
image_Content.buttonMode=true;
imageP1_Content.addChild(imageP1);
image_Content.addChild(imageA1_Content);
image_Content.addChild(imageP1_Content);
addChild(image_Content);
//

// Set Drag Function.
imageP1.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);

function drag(event:Event):void {
	image_Content.startDrag();
	imageA1.alpha=.2;
}
function drop(event:Event):void {
	image_Content.stopDrag();
	imageA1.alpha=0;
}
//