Link to home
Start Free TrialLog in
Avatar of skibama1
skibama1

asked on

Snap to Movie Clips

I have a movie that has 10 movie clip objects.  Each object has a different letter.  The objective here is that a student can click on a button, here a word and then try to spell the word by dragging the letters to boxes.  What I would like to happen is for the letters to snap to the center of the box once the letter is released on top of that box.

Right now once the release happens the letters just lay where they are dropped.

Example:

http://planetallison.com/ee/snapto/dls3.swf

Avatar of Calron
Calron

what you can do is add some positioning code when you stop the dragging:

somewhere in your code you have:

mc.stopDrag();

// calculate corrected position (snap to a grid)
mc._x = correctedX
mc._y = correctedY


Now to calculate the corrected position I'll give you a simple example that snaps to a 100x100 pixel grid

var correctedX = int(mc._x / 100) * 100;
var correctedY = int(mc._y / 100) * 100;

What this does is the following:  lets say my _x is 145.   145 / 100 = 1.45;  int(1.45) = 1; 1 * 100 = 100;
This of course can be refined a lot. In your case you will probably have to first check if the letter was released in the top part where you have the spaces to insert letters. If not, I would return the letter to its starting position at the bottom. The same for letters dropped somewhere outside of the top part.
In the top part define your grid where you want to  snap your letters to and do the calculations.
Avatar of skibama1

ASKER

OK, how do I go about changing the _X and _Y properties of the object?  I was assuming it would be:

setProperty("instance", _X, "xvalue");

but I nothing happens on the release
ASKER CERTIFIED SOLUTION
Avatar of Calron
Calron

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The _root solved the problem.  I also had to go back and set the _x & _y variables to calculate it based on the root.

That is:

var1 = _root.instance._x

instead of:

var1 = instance._x

Thanks for your help!!