Drag and Drop

Dragging constrains

Very often the application interface designed in such a way that dragging the object all around the stage is not desirable. Usually it's a restricted area where object is draggable.

Let's add the following amendments in our previous file

on(press) {
	startDrag(this, true, 50,50,200,150);
	thetext="thank you";
}
on(release) {
	stopDrag();
	thetext="drag me";
}

In the startDrag method of the movie clip this says that we will be dragging "myself" – or what it's clicked. true is a "lock" – a parameter that says that when dragged the movie symbol will stick to the mouse by it's center even if you click its at the edge. For larger draggable objects sometimes it's better to install it to "false". The last four numbers are left, top, right and bottom coordinates of the rectangle where movie is draggable – they are called constrains. . Those coordinates belong to the parent movie of the movie clip. So if our movie clip stays on the main timeline – constrains will be measured in the stage coordinate.

Next