0

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>

JoseK
  • 31,141
  • 14
  • 104
  • 131
Abhilash Muthuraj
  • 2,008
  • 9
  • 34
  • 48
  • 1
    What's wrong with the code? It doesn't work. (Tell us what you mean by "did not work", and we'll be more able to tell you how to fix it.) – LarsH Sep 21 '10 at 05:06
  • when i invoke drawcirle() method from button, circle was not rendered. So i tried with creationComplete(), it also failed. – Abhilash Muthuraj Sep 21 '10 at 12:15
  • When i tried the same actionscript code under File->new actionscript project, its working fine!! how do i get it working in a flex project?? – Abhilash Muthuraj Sep 21 '10 at 12:26

2 Answers2

2

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
  • 64,916
  • 15
  • 117
  • 140
0
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
  • 9,539
  • 2
  • 27
  • 31
  • That's not what the docs are saying. No `endFill` call - no fill. – LiraNuna Sep 22 '10 at 08:51
  • 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 Sep 22 '10 at 10:01