Text Drag (StackOverflow)
HTML
<script src="https://code.createjs.com/createjs-2015.05.21.combined.js"></script>
<h2>Constrain position to bounds</h2>
<p id="output">Output:</p>
<canvas id="canvas" width="800" height="600"></canvas>
JavaScript
var stage = new createjs.Stage("canvas");
var textFront = new createjs.Text("Hello World", "bold 24px Arial");
var textBounds = textFront.getBounds();
var textBoundary = new createjs.Shape();
textBoundary.graphics.beginStroke("#999")
.setStrokeStyle(1)
.drawRect(82, 130, 249, 240);
textBoundary.snapToPixel = true;
textBoundary.setBounds(82, 130, 249, 240);
var bounds = textBoundary.getBounds();
stage.addChild(textBoundary, textFront);
textFront.on("pressmove",function(evt) {
evt.currentTarget.x = Math.max(bounds.x, Math.min(bounds.x+bounds.width-textBounds.width, evt.stageX));
evt.currentTarget.y = Math.max(bounds.y, Math.min(bounds.y+bounds.height-textBounds.height, evt.stageY));
stage.update();
document.getElementById("output").innerHtml = bounds.x;
});
textFront.x = bounds.x, textFront.y = bounds.y;
stage.update();