Search code examples
apache-flexgraphicsprimitive

Find if a point is inside or outside flex primitive objects


I have some shaped created using flex primitive classes like ellipse , rectangle, path etc.

How can I find if a point is inside or outside these objects? (I need only the content area, not the transparent part.)


Solution

  • The hitTestPoint function is what you are looking for. Specify 3rd argument as true,and it will do the trick.

    UPDATE: You need to wrap primitives by Graphic element, then perform checking with that element. Example:

    <s:Graphic id="myEllipse">
        <s:Ellipse height="100" width="200">                              
            <s:stroke>
                <s:SolidColorStroke color="#000000" weight="1"/>
            </s:stroke>
            <s:fill>
                <s:SolidColor color="#0000FF"/>
            </s:fill>
        </s:Ellipse>
    </s:Graphic>
    
    //......
    myEllipse.hitTestPoint(someX,someY,true)