Take the 2-minute tour ×

enter image description hereI created a shape. It will be a room.

here is the code:

        room = new Sprite();
        room.graphics.beginFill(0xFFFF00, 1);
        room.graphics.moveTo(0, 0);
        room.graphics.lineTo(0, 500);
        room.graphics.lineTo(500, 500);
        room.graphics.lineTo(500, 250);
        room.graphics.lineTo(300, 250);
        room.graphics.lineTo(300, 0);

and i have a red rectangle at the middle. I wanna know which wall and two point is close to this rectangle. For example: in this screenshot left wall is nearest.

Thank you

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

This is not an actionscript question at all. You need just an algorithm.

Simple solution: find center of the object and then use any line distance algorithm you can find to check this center point distance to all room edges.

For example this: Shortest distance between a point and a line segment

share|improve this answer
I would add to this that to be able to check your room and red rectangle you need to store it as collection of points which then you will be able to run through and compare. –  Lukasz 'Severiaan' Grela Oct 4 '12 at 11:55
add comment

Your Answer


