I'm seeing some weird behavior with hitTestPoint. It should be reproducible with the attached code.
If I move a display object and use hitTestPoint afterward on the same frame against a point within the object's new shape bounds, I get false no matter what. On the following frame I get true like I should. If I then move the object away and in the same frame hitTestPoint against a point which is NO LONGER in the current shape (since it moved) but WAS in the shape on the previous frame, I sometimes get true and sometimes get false. This seems totally screwed up. Am I going mad? I've tried the move and hitTestPoint in both mouse handles and enterFrame handlers, but enterFrame handler is the only one I really care about at the moment.
Check out the following code; click to define a new position for the large object, then in the next entetFrame event it will move it and perform hitTestPoint -- object turns orange when hitTestPoint is true. You should see the same weird behavior described above.
Any suggestions other than throwing away hitTestPoint and using some mathematical approximation?
ActionScript Code:
var circ:Shape = new Shape();
circ.graphics.beginFill(0x009900);
circ.graphics.drawCircle(0, 0, 30);
addChild(circ);
var dot:Shape = new Shape();
dot.graphics.beginFill(0xFF0000);
dot.graphics.drawCircle(0, 0, 2);
dot.x = 250;
dot.y = 250;
addChild(dot);
stage.addEventListener("mouseDown", mouseDown);
stage.addEventListener("enterFrame", enterFrame);
var clicked:Boolean = false;
function mouseDown(e){
clicked = true;
}
function enterFrame(e){
if(clicked){
clicked = false;
circ.x = mouseX;
circ.y = mouseY;
var hit:Boolean = circ.hitTestPoint(dot.x, dot.y, true);
circ.transform.colorTransform = new ColorTransform(1,1,1,1,hit ? 0xFF : 0);
trace(hit)
}
}