views:

436

answers:

4

Hi!

I have a question that might seem "basic" but I just cannot figure out how to do it...

I have a box and I'd like to change the borderColor. Till there, nothing special. Just a box.bordercolor = xxxxxx...

BUT, I'd like to have the top and bottom border with one color, and the left and right border with another color... And that's the part where I'm stuck.

Any tips? Suggestions?

Thanks for your help and time! ;)

Regards, BS_C3

A: 

I'm pretty sure you're going to have to create a borderSkin to accomplish this. I believe these are created in an external program, such as Flash Professional; but more info is in the docs.

www.Flextras.com
A: 

I don't think that Flex makes any distinction between top/bottom borders and left/right borders. Creating a skin would certainly be the nifty-slick way to do it. A programmatic way might be to use box.graphics to draw your border by hand. I'd start by trying to override the updateDisplayList() function to draw your border...

Kelsey Rider
Hi! thanks both for your answers.However, how do I draw the borders using box.graphics?I've been looking into it but don't really get it. I found this:http://livedocs.adobe.com/flex/3/html/help.html?content=skinning_8.htmlbut stil... @____@If you could enlighten me, that would be great =P
BS_C3
+1  A: 

I noticed you are asking about the Flex 3 SDK. Skins are a good approach. They have changed somewhat in Flex 4(for the better IMHO). If you are wanting to use the Flex Drawing API, then just extend the Box class into a custom class that would look something like this:

public class MultiColorBorderBox extends Box
    {
                // You could add getters/setters or constructor parameters to be able to change these values.
            private var topColor:uint   = 0xFF0000;
            private var rightColor:uint = 0x00FF00;
            private var bottomColor:uint = 0x0000FF;
            private var leftColor:uint = 0xFF00FF;
            private var borderWidth:Number = 20;


        public function MultiColorBorderBox()
        {
            super();

        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            // This just ensures you dont have content under your border
            this.setStyle("paddingLeft", borderWidth);
            this.setStyle("paddingRight", borderWidth);
            this.setStyle("paddingTop", borderWidth);
            this.setStyle("paddingBottom", borderWidth);

            var g:Graphics = this.graphics;  // This creates a new Graphics object and sets it to the MultiColorBorderBox graphics object.  Since Box (superclass) descends from a Sprite object, it has a graphics object automatically.

            g.clear();
            g.moveTo(0,0);  // Moves the position to the top left corner
            g.lineStyle(borderWidth, topColor); // Sets the line style with the width and color
            g.lineTo(unscaledWidth, 0); // Draws the top border from top left to top right corners
            g.lineStyle(borderWidth, rightColor); // Changes the line style
            g.lineTo(unscaledWidth, unscaledHeight); // Draws the line from top right to bottom right
            g.lineStyle(borderWidth, bottomColor); //Changes the bottom border style
            g.lineTo(0, unscaledHeight); // Draws the line from bottom right to bottom left
            g.lineStyle(borderWidth, leftColor); // Changes the border color
            g.lineTo(0,0); // Closes the box by drawing from bottom left to top left            

        }
Shawn Yale
A: 

Hi!

I finally did a pretty simple thing. I guess I wasn't detailed enough regarding the specifications.

The actual aim was to create a navigator with arrow shaped buttons. Each button had to be highlighted when it was selected. And this is how the navigator looked like.

Each button is actually an HBox containing a Box (with a label) and an Image (for the arrow tip), with a horizontalGap = 0.

I didn't think about adding a glowfilter to the button. So I was trying to just change the colors of the top and bottom part of the Box...

So, the glowfilter in the button worked pretty well.

Sorry for the lack of explanations about the context >_< And thanks for your answers!!

Regards.

BS_C3