I would like for a movie clip to only snap to grind points that detected the hit test.
Here is my attempt…
var intXPos:Number = box.x
var intYPos:Number = box.y
myPoint.addEventListener(MouseEvent.MOUSE_DOWN, startEvent)
function startEvent(e:MouseEvent){
//stage.addEventListener(Event.ENTER_FRAME, drawPath);
stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPath);
}
myPoint.addEventListener(MouseEvent.MOUSE_UP, stopEvent)
function stopEvent(e:MouseEvent){
//stage.removeEventListener(Event.ENTER_FRAME, drawPath);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPath);
//removeChild(hitArray[k]);
}
function drawPath(e:Event):void{
var len:uint = hitArray.length
var blueRect:Rectangle = myPoint.getBounds(this);
var blueOffset:Matrix = myPoint.transform.matrix;
blueOffset.tx = myPoint.x - blueRect.x;
blueOffset.ty = myPoint.y - blueRect.y;
var bLoc:Point = new Point(blueRect.x, blueRect.y);
var myPointBmpData = new BitmapData(blueRect.width, blueRect.height, true, 0);
myPointBmpData.draw(myPoint, blueOffset);
var ham:*
var rLoc:Point = new Point()
for (var m:int=0; m<len; m++) {
ham = hitArray[m]
var redRect:Rectangle = ham.getBounds(this);
var redClipBmpData = new BitmapData(redRect.width, redRect.height, true, 0);
var redOffset:Matrix = ham.transform.matrix;
redOffset.tx = ham.x - redRect.x;
redOffset.ty = ham.y - redRect.y;
redClipBmpData.draw(ham, redOffset);
rLoc.x = redRect.x
rLoc.y = redRect.y
if(redClipBmpData.hitTest(rLoc,
255,
myPointBmpData,
bLoc,
255
))
{
//trace("hit");
ham.visible = true;
box.x = ham.x;
box.y = ham.y;
}
else
{
ham.visible = false;
//removeChild(ham);
}
}
myPointBmpData.dispose();
redClipBmpData.dispose();
}
box.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag)
function beginDrag(e:MouseEvent){
e.target.startDrag();
}
box.addEventListener(MouseEvent.MOUSE_UP, endDrag)
function endDrag(e:MouseEvent){
e.target.stopDrag();
e.target.x = intXPos;
e.target.y = intYPos;
}