How to draw a circle inside Border Container using graphics object?

1.6k views Asked by At

My basic requirement is to draw a circle inside a BorderContainer with the layout set to BasicLayout

I run this method in the CREATION_COMPLETE event of the BorderContainer object.

   this.graphics.beginFill(0xff0000);
   this.graphics.lineStyle(1, 0x00ff00);
   this.graphics.drawCircle(0, 0, 50);
   this.graphics.endFill();

Sorry to be blunt, but why don't I see anything? I know I must be missing something VERY basic here. Can I just draw like this OR should I draw in some other event?

P.S: I know that I can create a Ellipse object and easily add it to the border container but I would like to know how I can do this using the graphics object.

3

There are 3 answers

2
Wade Mueller On BEST ANSWER

Back in the olden days you would override updateDisplayList and do this sort of drawing there. I'm guessing things are getting refreshed at some point AFTER creation complete. Since you are drawing rather than adding an object to the stage, your circle isn't really part of any kind of lifecycle and will get wiped clean whenever the display list is dirtied/redrawn. Hope that helps.

0
Zeeshan On
var _shape:Shape=new Shape();
addchild(_shape);

_shape.graphics.lineStyle(1, 0x000000, 1);
_shape.graphics.drawRect(10,5,100,100);

Using the above code will show a rectangle on your screen.

0
Igor Milla On

I see two possible problems.

  1. you forget to add BorderContainer object to the stage
  2. this is no reference of your BorderContainer object. Try to trace this in your event listner, or change it to target or currenTarget