# Rounded rectangle class not working

**URL:** <https://forum.kirupa.com/t/rounded-rectangle-class-not-working/218529>\
**Category:** Uncategorized\
**Created:** [March 8, 2007, 3:24pm UTC](https://forum.kirupa.com/t/rounded-rectangle-class-not-working/218529 "2007-03-08T15:24:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabe243](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kabe243/32/3423_2.png) [@kabe243](https://forum.kirupa.com/u/kabe243)\
**Post date:** [March 8, 2007, 3:24pm UTC](https://forum.kirupa.com/t/rounded-rectangle-class-not-working/218529/1 "2007-03-08T15:24:30Z")

</div>

hi all, so i wrote this rounded rectangle class that can draw rounded rectangles with either a solid or a gradient fill. drawing solid rect causes no prblems at all, but the ones with a gradient fill just won’t work… i’m lost… especially because i could draw them easily before with a function… maybe its something really obvious, but i thought its a nice class that probably many people could use, so i put it here for everyone. any help appreciated.

here is the class:

```auto
 class DrawRoundedRect
{
    public var mc:MovieClip;
    private var x:Number;
    private var y:Number;
    private var w:Number;
    private var h:Number;
    private var cornerRad:Number;
    // --------------------------------------
    private var fill:Object = {};
    // --------------------------------------
    private var stroke:Object = {};
    /////////////////////////////////////////////////////////////////
    public function DrawRoundedRect(props:Object)
    {
        mc = props.mc;
        x = props.x;
        y = props.y;
        w = props.w;
        h = props.h;
        cornerRad = props.cornerRad;
        // --------------------------------------
        if (props.fill.type == "solid")
        {
            fill.color = props.fill.color;
            fill.alpha = props.fill.alpha;
        }
        else if (props.fill.type == "gradient")
        {
            fill.gradType = props.fill.gradType;
            fill.colors = props.fill.colors;
            fill.alphas = props.fill.alphas;
            fill.ratios = props.fill.ratios;
            //
            fill.matrix = {};
            fill.matrix.type = props.fill.matrix.type;
            fill.matrix.x = props.fill.matrix.x;
            fill.matrix.y = props.fill.matrix.y;
            fill.matrix.w = props.fill.matrix.w;
            fill.matrix.h = props.fill.matrix.h;
            fill.matrix.rad = props.fill.matrix.rad;
        }
        // --------------------------------------
        if (props.stroke)
        {
            stroke.w = props.stroke.w;
            stroke.color = props.stroke.color;
            stroke.alpha = props.stroke.alpha;
        }
        // --------------------------------------       
        createRect(props.fill.type, props.stroke);
    }
    /////////////////////////////////////////////////////////////////
    private function createRect(fillType:String, strokeBool:Boolean):Void
    {
        mc._x = x;
        mc._y = y;
        // --------------------------------------
        if (strokeBool && stroke.width != 0)
        {
            mc.lineStyle(stroke.width, stroke.color, stroke.alpha);
        }
        // --------------------------------------       
        if (fillType == "solid")
        {
            mc.beginFill(fill.color, fill.alpha);
        }
        else if (fillType == "gradient")
        {
            mc.beginGradientFill(fill.gradType, fill.colors, fill.alphas, fill.ratios, fill.matrix);
        }
        // --------------------------------------
        mc.moveTo(0 + cornerRad, 0);
        mc.lineTo(w - cornerRad, 0);
        mc.curveTo(w, 0, w, cornerRad);
        mc.lineTo(w, h - cornerRad);
        mc.curveTo(w, h, w - cornerRad, h);
        mc.lineTo(0 + cornerRad, h);
        mc.curveTo(0, h, 0, h - cornerRad);
        mc.lineTo(0, 0 + cornerRad);
        mc.curveTo(0, 0, 0 + cornerRad, 0);
        mc.endFill();
    }
    /////////////////////////////////////////////////////////////////
}

```

and here is how i call it:

```auto
 var rectShineObj:Object = {};
// --------------------------------------
rectShineObj.mc = this.createEmptyMovieClip("rectShineMC", this.getNextHighestDepth());
// --------------------------------------
rectShineObj.x = 102;
rectShineObj.y = 152;
rectShineObj.w = 296;
rectShineObj.h = 100;
rectShineObj.cornerRad = 8;
// --------------------------------------
rectShineObj.fill = {};
rectShineObj.fill.type = "gradient";
rectShineObj.fill.gradType = "linear";
rectShineObj.fill.colors = [0xFFFFFF, 0xFFFFFF];
rectShineObj.fill.alphas = [25, 0];
rectShineObj.fill.ratios = [0, 255];
// --------------------------------------
rectShineObj.fill.matrix = {};
rectShineObj.fill.matrix.type = "box";
rectShineObj.fill.matrix.x = 0;
rectShineObj.fill.matrix.y = 0;
rectShineObj.fill.matrix.w = 296;
rectShineObj.fill.matrix.h = 100;
rectShineObj.fill.matrix.rad = 90 / 180 * Math.PI;
// --------------------------------------
var gradRectrawRoundedRect = new DrawRoundedRect(rectShineObj);

```
