PDA

View Full Version : Drag and Drop Question


elisha
06-14-2001, 05:18 PM
Hi All,

I'm very new to action scripting and could really use some help!

I am trying to create a jigsaw puzzle (with the classic puzzle piece shape) in Flash and I want the user to drag and drop pieces to a specific location in the puzzle. If they drop a puzzle piece into the right location I want the piece to lock into place and a sound to be played.

So far I am able to do most everything except lock the piece in place. I don't want the user to be able to move a piece once he/she has placed it in the right location. Is it possible to lock it and stop the drag action for that particular piece? Thanks for any advice!

Cheers,

Elisha

20 Ton Squirrel
06-14-2001, 06:48 PM
Jesse's site has a great example of this on the Draco & Friends stuff (my son loves it). You should check it out.
Anyhoo... first get the exact coordinates for each peace, or at least a bounding box worth of coordinates. In the code for the release, you should have it check to see if the dragged MC is within the range of the target coordinates. Very simple stuff. It'll look something like this:

Define within each piece the range of coordinates you want it to snap to...
dest_x1, dest_x2, dest_y1, dest_y2

on (release) {
if ((pzlpc1._x >= pzlpc1.dest_x1 && pzlpc1._x <= pzlpc1.dest_x2) &&(pzlpc1._y >= pzlpc1.dest_y1 &&pzlpc1._y <= pzlpc1.dest_y2)) {
setProperty (pzlpc1, _x, 131.7); // point x to snap
setProperty (pzlpc1, _y, 296.3); // point x to snap
} else {
setProperty (pzlpc1, _x, 450); // point of x origin
setProperty (pzlpc1, _y, 250); // point of y origin
}
}

Hope that helps ya... I adapted that code from a F4 paperdoll project of mine and it worked beautifully.

[Edited by 20 Ton Squirrel on 06-14-2001 at 01:54 PM]