SO this may be an easy solution, but I can't seem to figure it out myself. What I am doing, is creating a drag n drop game, and it's all well and beautiful, but if you let go of the piece too early, it automatically snaps to the nearest available location (based on positions I have in an array to choose from). I'm really looking for it only to snap if it's say within the confines of the movieclip it's over, or if it's within a 20px radius of a movieclip. Hope you guys can help me! It is inititated on a mouseUp event.
Code:
var dragArray:Array = [it_1, it_2, it_3, it_4, it_5, it_6, it_7, it_8, it_9];
var matchArray:Array = [mat_1, mat_2, mat_3, mat_4, mat_5, mat_6, mat_7, mat_8, mat_9]
var placeArray:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8];
// points to snap to
var pointList:Array = new Array();
pointList.push(new Point(mat_1.x, mat_1.y));
pointList.push(new Point(mat_2.x, mat_2.y));
pointList.push(new Point(mat_3.x, mat_3.y));
pointList.push(new Point(mat_4.x, mat_4.y));
pointList.push(new Point(mat_5.x, mat_5.y));
pointList.push(new Point(mat_6.x, mat_6.y));
pointList.push(new Point(mat_7.x, mat_7.y));
pointList.push(new Point(mat_8.x, mat_8.y));
pointList.push(new Point(mat_9.x, mat_9.y));
////where points are placed after being snapped to
var spliced:Array= new Array();
function SnapEvent(event:MouseEvent) {
//// the clip we're dragging////
var referencePoint:Point = new Point(currentClip.x, currentClip.y);
var resultPoints:Array = PointTester.findClosest(referencePoint, pointList, 1);
////returns nearest "mat" and snaps current clip to it////
for each(var result:Object in resultPoints) {
//trace("Point is at:", result.point.x, ", ", result.point.y, " that's ", result.distance, " units away");
currentClip.x=result.point.x;
currentClip.y=result.point.y;
var posOfMat:int = pointList.indexOf(result.point);
trace("index: "+pointList[posOfMat]);
spliced.push(pointList[posOfMat]);
pointList.splice(posOfMat,1);
//trace("spliced: "+spliced);
trace("length: "+pointList.length);
}
//trace("result: "+result.point);
trace("full spliced: "+spliced.length);
}