Currently, I am using the code below. But it is telling me that the circle is starting to hit the line when it’s y position is 40. But since the circle actually isn’t crossing the line itself (virtually) until it’s y position is at about 205, I don’t want the trace-action called so early.
I know that there exists a “hitArea” property of all DisplayObjects (Sprites included), but I don’t know if - or how - I could use it to fix this situation.
var circle: Sprite = new Sprite();
circle.graphics.beginFill(0xFF0000);
circle.graphics.drawCircle(0, 0, 10);
circle.x = 170;
circle.y = 30;
addChild(circle);
var line: Sprite = new Sprite();
line.graphics.lineStyle(1, 0xFF0000);
line.graphics.lineTo(200, 200);
line.y = 50;
addChild(line);
addEventListener(Event.ENTER_FRAME, fncTestHit);
function fncTestHit(event: Event) {
circle.y += 1;
if (circle.hitTestObject(line)) trace('hits line at '+circle.y);
if (line.hitTestObject(circle)) trace('hits unit at '+circle.y);
}