开发者

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

开发者 https://www.devze.com 2023-02-21 23:40 出处:网络
My basic requirement is to draw a circle inside a BorderContainer with 开发者_如何学JAVAthe layout set to BasicLayout

My basic requirement is to draw a circle inside a BorderContainer with 开发者_如何学JAVAthe 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.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消