School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,466 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,706 people online right now. Registration is fast and FREE... Join Now!




Frustrated with AS3 OOP

 

Frustrated with AS3 OOP, Fill a rounded Rectangle with a gradient

WhidbeyTomas

21 May, 2009 - 01:09 PM
Post #1

New D.I.C Head
*

Joined: 21 May, 2009
Posts: 1

Hey folks, I'm trying to build a class that creates a rounded rectangle with a linear gradient fill (vertical). I think I'm close, but the cigar won't come. Here is the code so far. I'm not sure where I tell flash that I want a rounded rectangle.

I'm hoping someone can help me out here. Here is the code so far:
CODE
package org.keelworks.utils
{
    /**
     * ...
     * @author Thomas Garrod
     */
    public class GRecGradient extends Sprite
    {
        import flash.display.Sprite;
        import flash.geom.Matrix;
        public var gRecWidth:uint;
        public var gRecHeight:uint;
        public var xPos:Number;
        public var yPos:Number;
        public function GRecGradient (grRecWidth:uint, gRecHeight:uint, xPos:Number, yPos:Number)
        {
            Box();
        }
        public function Box ()
        {
            var matrix:Matrix = new Matrix();
            trace(matrix.toString());          // (a=1, b=0, c=0, d=1, tx=0, ty=0)
            matrix.createGradientBox(gRecWidth:uint, gRecHeight:uint, 0, xPos, yPos);
            trace(matrix.toString());          // (a=0.1220703125, b=0, c=0, d=0.1220703125, tx=150, ty=150)
            var colors:Array = [0xFF0000, 0x0000FF];
            var alphas:Array = [100, 100];
            var ratios:Array = [25, 255];
            var gBox:Sprite = new Sprite;
            gBox.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, myMatrix);
            addChild(gBox);
        }
    }
}




User is offlineProfile CardPM
+Quote Post


SoLi

RE: Frustrated With AS3 OOP

22 May, 2009 - 12:33 AM
Post #2

andydust.com
*****

Joined: 27 Jan, 2002
Posts: 1,428



Thanked: 35 times
My Contributions
After beginning your gradient fill you need to draw the shape (and then end it if you so wish).

here's what's missing from your code, as far as i can tell.

CODE

gBox.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, myMatrix);

// new code :)
gBox.graphics.drawRoundRect(0, 0, YOUR_WIDTH, YOUR_HEIGHT, YOUR CORNER_RADIUS);
gBox.graphics.endFill();
// end new code

addChild(gBox);


I guess you probably want the drawRoundRect width and height values to match those you used on the createGradientBox method of your matrix, so just copy across those variables i guess smile.gif

This post has been edited by SoLi: 22 May, 2009 - 12:34 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:34AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month