# How to determine draging area?

This prolly a silly question, but how do you guys determine the drag parameters when setting up a dragable item in flash mx? Not sure if im using correct terminolgy but what if refering to is the ’ constrain to rectangle ’ and ’ lock to center parameters ’ on the startDrag cmd. Right now I am just plugging in numbers until I get the results I want – must be a better way :).

Thanks!

Constrain to rectangle constrains to a rectangle, it won’t let you drag outside that area.
Lock to center locks the drag to center. The mouse is at the center of the clip.

pom

Thanks for the reply Pom! What I meant is whats the best way to figure out the cordinates to use for these values.

Say with this scenerio. My main MC is 400x400 and I am importing a external MC thats 100x100. Well I like to set it up so you can drag the external MC but not outside the boundaries of the main MC. Ok, Im familiar with the ‘Constrain to rectangle’ function but not really sure on how to figure an easy way of coming up with the cordinates to use. Hope that makes sense.

Thanks!

Well, you’d have to calculate the boudaries of the big clip, and make so that the small clip cannot get out.

An example: put a big square on your scene, movie clip, and instance name big. Then a small square, instance name small.

Then put this code in the first frame of the main movie:

``````// calculates edges of BIG
bigTop=big._y-big._height/2;
bigLef=big._x-big._width/2;
bigBot=big._y+big._height/2;
bigRig=big._x+big._width/2;

// calculates real top, left... so that small remains in big
top=bigTop+small._height/2;
left=bigLef+small._width/2;
bottom=bigBot-small._height/2;
right=bigRig-small._width/2;

small.onPress=function(){
this.startDrag(false,left,bottom,right,top);
}
``````

Post if you have problems with the code.

pom :cowboy: