以下是我目前使用的代碼。現在我只想讓它畫一個正方形並顯示出來。現在,當我點擊MXML中定義的區域<components:PaintArea width="100%" height="100%" id="paint-a"></PaintArea>
時,它什麼都不顯示;然而,actionlistener正在被觸發並且一個元素被添加到組中。不確定究竟發生了什麼......也許由於某種原因,它不認爲該元素是可繪製的?無論如何感謝您的幫助!嘗試在Flex4/AS3中向自定義容器繪製矩形
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);
}
}
哇...是啊,咄!謝謝 :)! – Parris 2010-04-01 07:27:34