views:

64

answers:

2

I'm using flex sdk and trying to draw primitive geometry figures, what is wrong in following code? i tried without the trigger(placing) of button, but did not work.

 <mx:Script>
     import flash.display.Sprite;
     import flash.display.Shape;

     private function draw_circle():void
     {
         var myCircle:Shape = new Shape();
         myCircle.graphics.beginFill(0x00000, 1);
         myCircle.graphics.drawCircle(0, 0, 30);


         addChild(myCircle);
     }


 </mx:Script>

  <mx:Button x="30" y="0" name="circle" click= '{draw_circle()}'>



 </mx:Button>

+2  A: 

You need to endFill after you beginFill:

private function draw_circle():void
{
    var myCircle:Shape = new Shape();
    myCircle.graphics.beginFill(0x00000, 1);
    myCircle.graphics.drawCircle(0, 0, 30);
    myCircle.graphics.endFill();
    addChild(myCircle);
}

Appropriate documentations could be found here.

The fill is not rendered until the endFill() method is called.

LiraNuna
A: 
private function draw_circle(event:Event):void
{
   var myCircle:Shape = new Shape();
   myCircle.graphics.beginFill(0x00000, 1);
   myCircle.graphics.drawCircle(0, 0, 30);
   myCircle.graphics.endFill();


   addChild(myCircle);
}

also...

<mx:Button x="30" y="0" name="circle" click= 'draw_circle(event);'>

If you don't specify endFill(), you're likely to run into important memory problems but the circle should still be drawn though

PatrickS
That's not what the docs are saying. No `endFill` call - no fill.
LiraNuna
my mistake, i thought it would render (similarly to lineStyle) but create a memory leak... by the way , i didn't omit endCircle intentionally in my example, I certainly wouldn't like to suggest that it's not needed!
PatrickS