0

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.

Wade Mueller
  • 6,059
  • 17
  • 19
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128

3 Answers3

2

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
Igor Milla
  • 2,767
  • 4
  • 36
  • 44
2

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.

Wade Mueller
  • 6,059
  • 17
  • 19
  • The issue I had is, I could create a new Ellipse object and then add it to BordnerContainer. It works, but also it makes the application painfully slow. – Ranhiru Jude Cooray Apr 08 '11 at 04:40
  • In that case I would move your drawing code to an overridden updateDisplayList function for your BorderContainer. – Wade Mueller Apr 08 '11 at 16:20
0
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.

ronalchn
  • 12,225
  • 10
  • 51
  • 61