Sorry. Totally forgot about the constraints. You can create a utility function like the one below and apply it to the onDrag function or you can add a couple of if statements like suggested by @kglad .
function onStartDrag(e)
{
var target = e.currentTarget;
target.offset = { x: e.stageX / stage.scaleX - target.x, y: e.stageY / stage.scaleY - target.y };
}
function onDrag(e)
{
var target = e.currentTarget;
var rec = target.dragRectangle;
target.x = clamp(rec.left, e.stageX / stage.scaleX - target.offset.x, rec.right);
target.y = clamp(rec.top, e.stageY / stage.scaleY - target.offset.y, rec.bottom);
}
function clamp(min, value, max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}
createjs.Touch.enable(stage);
stage.mouseMoveOutside = true;
this.instanceYouWantToDrag.dragRectangle = { left: 38.75, top: 46.25, right: 526.35, bottom: 312.55 };
this.instanceYouWantToDrag.on("mousedown", onStartDrag);
this.instanceYouWantToDrag.on("pressmove", onDrag);