Abhilash Muthuraj
Abhilash Muthuraj

Reputation: 2028

drawing circle in flex

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>

Upvotes: 0

Views: 3126

Answers (2)

PatrickS
PatrickS

Reputation: 9572

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

Upvotes: 0

LiraNuna
LiraNuna

Reputation: 67252

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.

Upvotes: 2

Related Questions