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! 😀
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);
}
Sprite doesn’t implement IVisualComponent. (Check the docs: http://www.eonflex.com/flex/4.1/langref/flash/display/Sprite.html)
You need to add a UIComponent to hold the sprite.
Something like: