# When the puzzle is complete!

**URL:** <https://forum.kirupa.com/t/when-the-puzzle-is-complete/144902>\
**Category:** Uncategorized\
**Created:** [April 18, 2005, 11:27am UTC](https://forum.kirupa.com/t/when-the-puzzle-is-complete/144902 "2005-04-18T11:27:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsonn](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@johnsonn](https://forum.kirupa.com/u/johnsonn)\
**Post date:** [April 18, 2005, 11:27am UTC](https://forum.kirupa.com/t/when-the-puzzle-is-complete/144902/1 "2005-04-18T11:27:26Z")

</div>

I have been playing with a jigsaw puzzle example from :

“Macromedia Flash 5 ActionScript Fun and Games  
View Larger Image Gary Rosenzweig  
Que, Paperback, Published April 2001, 415 pages, ISBN 078972524X”

Here is the script, is there a way I can determine that once the puzzle is complete I could gotoAndPlay(x).

onClipEvent(mouseDown) {  
// get mouse location  
mx = \_root.\_xmouse;  
my = \_root.\_ymouse;

```
// loop through pieces looking for hit
for(x=0;x&lt;6;x++) {
	for(y=0;y&lt;4;y++) {
		piece = _root[x+"-"+y];

		// see whether the piece is under the cursor
		// and if it has not yet been placed
		if (piece.hitTest(mx,my) and (piece._alpha &lt; 100)) {
			// this is the piece clicked
			piece.startDrag();

			// break out of all loops
			x = 6;
			y = 4;
			
			gotoAndPlay(10);

```

;  
}  
}  
}  
}

onClipEvent(mouseUp) {  
// stop piece from moving  
stopDrag();

```
// get distance from center of piece
// to center of outline

dx = _root.outline._x - piece._x;
dy = _root.outline._y - piece._y;
dist = Math.sqrt(dx*dx+dy*dy);

// if close enough, then set it in place
if (dist &lt; 10 ) {
	piece._x = _root.outline._x;
	piece._y = _root.outline._y;

	// set to full color
	piece._alpha = 100;
}

```

}

thanks,tyjn
