title: Why is Flex SolidColorStroke acting that weird?
body: <p>I had to solve a problem concerning the SolidColorStroke of the flex framework. The scenario is simple, we have an visible object and we want a border around it. I built a graphics component that draws a <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/Rect.html" rel="nofollow noreferrer">Rect</a>. That Rect was defined as follows</p>
  
  <pre><code>object; // the object which should get the border, defined somewhere outside, 
          // just fyi
  
  
  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
  &lt;s:Rect id="rect"&gt;
    &lt;s:stroke&gt;
      &lt;s:SolidColorStroke id="rectStroke" /&gt;
    &lt;/s:stroke&gt;
  &lt;/s:Rect&gt;
  </code></pre>
  
  <p>I thought it should like this (just for illustration, not an exact image of what it should be, the border in this illustration is exactly around the object)</p>
  
  <p><img src="https://i.stack.imgur.com/oLtWT.png" alt="enter image description here"></p>
  
  <p>But I was wrong because the border did cover some parts of the objects on the right and on the bottom. My next thought was, that the stroke of the border doesn't grow inside the component, but on each side of the border in equally parts. What I mean by that is that when it grows inside the component and you place it at the location x = 0, y = 0 the width in my example of the left side of the border would be from 0 to 10. The thicker the border gets, the more it grows to the inside until there is just one big rectangle. </p>
  
  <p>When I say it grows equally to each part of the border I mean that if you place the rect on x = 0, y = 0 and your border is 10px thick, the left side of the border goes from -5 to 5.
  I hope it's clear what I mean.</p>
  
  <p>So, as I said before I thought the border grows equally to both parts of the stroke. So I changed the calculations of the width and height to:</p>
  
  <pre><code>rect.width = object.width + borderThickness;
  rect.height = object.height + borderThickness;
  </code></pre>
  
  <p>Now the width and height of the object is just increase the borderThickness (half of the borderThickness on every side). I thought now the border should fit exactly the object (as I expected it with my first version too...). </p>
  
  <p>It look better than the first version but still some parts on the right and the left of the object are covered. </p>
  
  <p>After a long time of thinking why it doesn't work as I expect I found a solution that worked for me. It seems that the stroke doesn't grow to equal parts on both sides, it seems that it grows by 75% to the inside and 25% to the outside. The following illustration shows what I mean by that.
  <img src="https://i.stack.imgur.com/bctCm.png" alt="enter image description here"></p>
  
  <p>The yellow line inside the border shows the actual border (when the stroke would be 1px). You can see that it is now exactly in the middle of the stroke but 75% from the inside and 25% from the outside. </p>
  
  <p>My Question is, does anybody experience a similar behavior? Does anyone know why that works the way it does. Am I using it correct? Or what am I doing wrong?</p>
  
  <p>The documentation of Adobe doesn't really tell you that the SolidColorStroke works this way. If you need more code, please let me know.</p>
  
  <p>kind regards<br />
  Markus</p>