AS3 add a border to a displayobject

Jimy picture Jimy · Jun 29, 2011 · Viewed 12.3k times · Source

I know how to draw a rectangle and add it to a DisplayObjectContainer, but do you see a simpler method to directly add a border to a DisplayObject?

DisplayObject don't seem to have addChild(), so I would have to add it on the parent, which is not perfect in my opinion...

Answer

citizen conn picture citizen conn · Jun 29, 2011

I would create a transparent fill shape and add it to the DisplayObject like this:

Edit :drawing directly to the DisplayObject

this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(0x000000, 0);
this.graphics.drawRect(0, 0, 50, 50);
this.graphics.endFill();