PDA

View Full Version : Get the hitTest mc name?


fauzira
03-07-2007, 05:10 AM
I've problem to get mc name when hitTest, for example:
I drag box_mc to circle_mc and when box_mc droped on top of circle_mc the box_mc will know the name of mc bellow. But I don't want use _droptarget because when we drag mc to other mc the mouse pointer must on top of both mc.

this my code using droptarget, but this not fix my problems. :(

stop();
box.onPress = function () {
this.startDrag();
};
box.onRelease = function () {
this.stopDrag();
trace(this._droptarget);
};

kiliaan856
03-07-2007, 06:16 AM
I don't think you are looking for a drop target function... you are looking more for a hitTest type of function. Here is what I would do... all of my movieclip objects that can receive dropped items I would store in an array, and perform a hit test on all of them on release. Example, assuming you had movieclips circle1 and circle2:



var hitArray:Array = [this.circle1, this.circle2];
box.onPress = function() {
this.startDrag();
};
box.onRelease = function() {
this.stopDrag();
for (i=0; i<hitArray.length; i++) {
if (this.hitTest(hitArray[i])) {
trace(hitArray[i]);
}
}
};

fauzira
03-07-2007, 06:45 AM
Thanks kiliaan :)
I've already using droptarget to get target moviclip properties (name,width,x,etc.). I'm making drag n drop games to assemble machine like jigsaw but more complex. for example I drag a pipe to part of machine and when I use _droptarget.. player having difficulties to snap it, because using droptarget we must released mouse pointer above target movieclip.

I've already make the script like that, but that need big change on script. I think thats the only way to solve this problem..

btw I see your website and playing your games it's fun :)