1. Always first call Shape.graphics.clear()
before you really draw anything. Here.
2. If you want your drawings to show up, besides adding your Shape/Sprite, etc object to the display list, you would need to specify either the lineStyle (by calling graphics.lineStyle(thinckness:Number=null, color:unit=0. alpha:Number=null, etc);)or the fillColor (by calling graphics.beginFill(color:uint, alpha:Number=null))or both before you draw anything, _after_ you did #1. For lineStyle, you will at least specify the thinkness; for fill, the color, both are the first parameter of the associated drawing function calls:
//draw a stroke in rectangle, without fill
var _rect1:Shape = new Shape();
_rect1.graphics.clear();
_rect1.graphics.lineStyle(1);
_rect1.graphics.drawRect(300,50, 200, 200);
addChild(_rect1);
//draw a solid rectangle, without stroke
var _rect2:Shape = new Shape();
_rect2.graphics.clear();
_rect2.graphics.beginFill(0);
_rect2.graphics.drawRect(300,50, 200, 200);
_rect2.graphics.endFill();
addChild(_rect1);
Leave a comment