2 Replies Latest reply on Jan 3, 2008 7:15 PM by peterent

    Drawing API - Remain on component

    texura
      I'm trying to build a component which uses the drawing api to draw half circles radiating up from the bottom. I draw the circle with the center point on the bottom of the component. The drawing api is happy to draw the circle with the bottom half of the circle below the component being drawn on. How can I avoid drawing outside the component which the graphic property is being used?
        • 1. Re: Drawing API - Remain on component
          atta707 Level 2
          you've height and width propeties of the component you're drawing on. You know where do you want to start. Given this data you should be able to calculate where do you want to stop drawing; or how big your half circle would be. Makes sense?
          • 2. Re: Drawing API - Remain on component
            peterent Level 2
            atta707 is correct with that information. If you don't want to worry about drawing within the boundaries you can add a clipping mask to the component.

            var clipper:Sprite = new Sprite();
            clipper.graphics.clear();
            clipper.graphics.beginFill(0);
            clipper.graphics.drawRect(0,0,unscaledWidth,unscaledHeight);
            clipper.graphics.endFill();

            Now assign this to the mask property of the component and add it as a child of the component:
            mask = clipper;
            addChild(clipper); // I don't remember off the top of my head if this step is necessary

            Put this code in your component's override of updateDisplayList(). You can create the clipper in the component's override of createChildren() if you don't want to create it in updateDisplayList().