Skip navigation
Currently Being Moderated

Why is SolidColorStroke acting acting that weird?

Jul 31, 2012 1:18 PM

Tags: #as3 #actionscript #air3 #spark #solidcolorstroke

Hi everybody,

 

(I posted this question on Stackoverflow, so if you want you can also read this post.)

 

Recently I had to build an MXML component, that adds a border around an object. That object is some visual object that is passed to the component. I use a Rect to draw the border. That Rect has a SolidColorStroke as child. The thickness of the border (the stroke) is configured by setting the strokes weight. My first solution to this problem looked something like this.

 

var borderThickness:Number = 10;   
rect
.x = object.x - borderThickness;
rect
.y = object.y - borderThickness;
rect
.width = object.width + (borderThickness * 2);
rect
.height = object.height + (borderThickness * 2);
rectStroke
.weight = borderThickness;

//the MXML code
<s:Rect id="rect">
 
<s:stroke>
   
<s:SolidColorStroke id="rectStroke" />
 
</s:stroke>
</
s:Rect>

 

I thought the x and y coordinate of the border is the x and y coordinates of the object minus the borderThickness. It seems that I was wrong because the border covers some parts of the object on the right and the bottom.

 

The next solution I had was that the stroke grows by 50% to each side. That means that if you want to calculate the x and y coordinate you just subtract the half borderThickness. I hope it's clear what I mean.

 

Also this didn't work correctly. I found out, that the stroke doesn't grow by 50% on each side but it grows by 75% to the inside and 25% to the outside. So now my code looks like this:

 

var borderThickness:Number = 10;   
rect
.x = object.x - borderThickness;
rect
.y = object.y - borderThickness;
rect
.width = object.width + (borderThickness * 1.5);
rect
.height = object.height + (borderThickness * 1.5);
rectStroke
.weight = borderThickness;

//the MXML code
<s:Rect id="rect">
 
<s:stroke>
   
<s:SolidColorStroke id="rectStroke" />
 
</s:stroke>
</
s:Rect>

 

My question now is, am I using it correct? Does anyone experience a similar behavior? Is that the correct behavior? What am I doing wrong?

 

kind regards

Markus

 
Replies
  • Currently Being Moderated
    Jul 31, 2012 3:31 PM   in reply to creak45

    I don't think you need to adjust the x/y positions manually. This is usually done automatically by the parent layout container. It really depends on what the rest of your code looks like though. My guess is you need to control a few things in your updateDisplayList method. Take a peek at the source for the spark PanelSkin.mxml for an example on how to control these kinds of things. If you are still stuck, post a complete example that demonstrates the issue.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points