1

How can i draw a shape, that is only rounded at it's bottom, without using libraries?

enter image description here

  var _myShape:Shape = new Shape();
      _myShape.graphics.lineStyle(4,0x000000,1,true,....);
      _myShape.graphics.drawRoundRect(0,0,50,50,10);
mate64
  • 9,876
  • 17
  • 64
  • 96

3 Answers3

1

See this page: Why is drawRoundRectComplex() not documented in ActionScript?

You need "drawRoundRectComplex"

EDIT: If you can't the Flex SDK, your only other "real" drawing option is to use a combination of lineTo and curveTo. The easiest way to do this is to copy the code from the GraphicsUtil class in the Flex SDK. I'm not clear if it's considered open-source or not, so I'm not going to post it here.

Community
  • 1
  • 1
Glenn
  • 5,334
  • 4
  • 28
  • 31
1

if you don't want to use Flex libraries (as you've commented on Glenn's answer) and if you're only concerned will fills, you could employ a masking technique on your sprites.

var sprite:Sprite = new Sprite();
sprite.graphics.beginFill(0xFF0000, 1.0);
sprite.graphics.drawRoundRect(0, 0, 300, 200, 100, 100);
sprite.graphics.endFill();

var spriteMask:Shape = new Shape();
spriteMask.graphics.beginFill(0);
spriteMask.graphics.drawRect(0, sprite.height / 2, sprite.width, sprite.height / 2);
spriteMask.graphics.endFill();

sprite.mask = spriteMask;
sprite.addChild(spriteMask);

addChild(sprite);

including strokes is a little trickier, but still possible.

Chunky Chunk
  • 16,553
  • 15
  • 84
  • 162
0

You can emulate a stroke by using a GlowFilter, although it will be more expensive than a true stroke.

You also don't need a mask -- just draw two boxes.

var s:Sprite = new Sprite;
addChild(s);

s.graphics.beginFill(0xff0000);
s.graphics.drawRoundRect(0,0,50,50,10);
s.graphics.endFill();

s.graphics.beginFill(0xff0000);
s.graphics.drawRect(0,0,50,20);
s.graphics.endFill();

s.filters = [new GlowFilter(0x0, 4, 8,8, 40)];
Chris Burt-Brown
  • 2,717
  • 1
  • 16
  • 16
  • GlowFilter will suffice for thin strokes, but it's not a solution for thick strokes as it becomes noticeably blurry or for strokes that must be clean and sharp. i wish the Graphics class had a proper stroke method - lineStyle() is just simply laughable. additionally, there's also the option to create 2 shapes for more control, but set the blendMode on the inside shape to BlendMode.ERASE. – Chunky Chunk Feb 17 '11 at 18:26