Trying to draw a Rectangle to a Custom Container in Flex4/AS3

Posted by Parris on Stack Overflow See other posts from Stack Overflow or by Parris
Published on 2010-04-01T07:08:09Z Indexed on 2010/04/01 7:13 UTC
Read the original article Hit count: 755

Filed under:
|
|
|
|

So below is the code I have so far. For now I simply want to make it draw a square and have it show up. Right now when I click the area defined in MXML as <components:PaintArea width="100%" height="100%" id="paint-a"></PaintArea> it shows nothing; however, the actionlistener is getting triggered and an element is being added to the group. Not sure exactly what is going on... perhaps for some reason it doesn't think the element is drawable? Anyways thanks for the help!

public class PaintArea extends SkinnableContainer
{
    private var canvas:Group;

    public function PaintArea()
    {
        super();
        canvas = new Group();
        canvas.clipAndEnableScrolling = true;
        canvas.percentHeight = 100;
        canvas.percentWidth = 100;
        canvas.addEventListener(MouseEvent.MOUSE_UP,drawRectangle);
        this.addElement(canvas);
    }

    private function drawRectangle(e:MouseEvent):void{
        var r:Rect = new Rect();
        r.fill = new SolidColor(0x00ff00,.5);
        canvas.addElement(r);
    }
}

© Stack Overflow or respective owner

Related posts about flex4

Related posts about flex