Hit test using Array

I am in the process of making a jigsaw game. For testing purposes, it is only a 4 piece, square puzzle. I have 4 seperate movie clips named one, two, three, and four.

I wanted to make it different than the other jigsaw puzzles I’ve seen in flash, and wanted to make it so that when you ‘connect’ pieces that go next to each other, they actually follow each other.

In each movie clip I have :


onClipEvent (mouseDown) {
	if (this.hitTest(_root._xmouse, _root._ymouse)) {
		this.startDrag();
	}
}

onClipEvent (mouseUp) {
this.stopDrag();
}


There is only one frame, and on the first frame’s actions I have :


stop ();


_root.one.onEnterFrame = function () {
	
if (_root.one.hitTest(_root.two)) {
	
xposition1 = getProperty("/one", _x);
yposition1 = getProperty("/one", _y);

setProperty(/two, _x, _root.one._x + 205);
setProperty(/two, _y, yposition1);
}
}

That code all works just fine ( I know I can clean it up a little, but I am not concered with neatness just yet. Once it is done I will clean up the code). What I am trying to do though is make it so that I can create an array and have it loop for the function of each movie clip. I have this code, yet don’t know exactly how to implement it:


	myArray = ["one", "two", "three", "four"];
	for (j=0; j < myArray.length; j++) {
		blah += myArray[j];

What I want is when a MC checks for a hitTest, I want a function for it to test which other MC it hit, rather than listing them each individually like in the first code snippet I showed. I don’t want to code for each instance, though I will, I just wondered if there’s a way to to do it with Arrays.

I am attaching a copy of the fla i’ve been workin on. Thanks so much. Heck, if theres a better way to do it too, let me know!

Bump

I’ll take a look at it tomorrow…

Peace Man

Thank you so much!

I seem to remember a few months ago some asked soemthing about a jigsaw fla… do a little search if you want, if you find it I’m sure it could help you out a bit.

Peace

instead of storing strings in the array, you can fill it with references to your clips. then movieArray[2] will reference the clip directly. then by cycling through that array you can apply a test to each clip.


movieArray = [_root.one,_root.two,_root.three,_root.four];

MovieClip.prototype.hitTestAll = function(){
   var i,a = [];
   for(i in movieArray){
      if(movieArray* != this){
         if(this.hitTest(movieArray*)){
            a.push(movieArray*);
         }
      }
   }
   return (a.length ? a : false)
}

that prototype will return an array containing all the clips which give a positive hitTest, if no clips give a hitTest, it returns false.

I think there is an example of a jigsaw with flash 5 atleast?