Drawing Shapes in Flex 4/AS3 addchild issues

Posted by Parris on Stack Overflow See other posts from Stack Overflow or by Parris
Published on 2010-03-31T00:42:56Z Indexed on 2010/03/31 1:43 UTC
Read the original article Hit count: 776

Filed under:
|
|
|
|

Hi All, I am simply trying to draw a rectangle inside of a panel using flex4. I am using spark instead of mx. It complains about addchild being replaced by addelement; however, addelement expects type ivisualcomponent. I think sprite should be of that type; however, it reports an error when trying to use the below code... I have tried a few different ways. I think I am missing something very basic about flex 4. Any enlightenment would be much appreciated! :-D

private function drawRectangle(e:MouseEvent):void{
    var s:Sprite = new Sprite();
    s.graphics.beginFill(0x00ff00, 0.5);
    s.graphics.drawRect(e.localX,e.localY,50,50);
    s.graphics.endFill();
    canvas.addChild(s);
}

© Stack Overflow or respective owner

Related posts about flex4

Related posts about flex