'snap to' tutorial?

Hi… again…

Anyone have a good tutorial for having an object snap to a position on the screen… I already have the objects dragging… I just want to know how I can take those draggable objects and have them snap to a target when you get close…

thanks again…

similar to a magnetic effect? i think Sinf gave a file like this before. let me try to find it and break it apart for you. or someone else might help first because I have classes for the next 7 hours today. I get to dissect a fetal pig…:expressionless: Not sure how i feel about that…sorry if that offends anyone :slight_smile:

in order to do this, you would need to use distance formula. in case you don’t know what it is, here it is:

function dist(x, y, x1, y1) {
x2 = Math.abs(x-x1);
y2 = Math.abs(y-y1);
return Math.sqrt(x2x2+y2y2);

…in actionscript. this lil function returns the distance between one object (its x and y) and any point (x1, y1) or object. the next thing you would have to do is test the distance between the point you want it to snap, and the object itself:

if (dist(_x, _y, 275, 200) <= 50) {
_x = 275;
_Y = 200;

now what this little piece of code would do is snap to the center of the screen when it is 50 pixels away from the center (assuming the size of your movie is the default, 550x400). do you understand? if not, email me ([email protected]) and i’ll try and pull off a sample fla for ya.