title: Flex: getting the height of a collection of controls
body: <p>Or putting it more accurately, I want to be able to get the distance between the top of a control to the top of one of its children (and adding the height member of all the above children yields specious results!) but the process of getting the absolute coordinates, and comparing them, looks really messed up.</p>
  
  <p>I use this function to calculate the height between the tops of 2 tags:</p>
  
  <pre><code>        private static function GetRemainingHeight(oParent:Container, oChild:Container,  
                              yParent:Number, yChild:Number):Number {
              const ptParent:Point = oParent.localToGlobal(new Point(0, yParent));
              const ptChild:Point = oChild.localToGlobal(new Point(0, yChild));
              const nHeightOfEverythingAbove:Number = ptChild.y - ptParent.y;
              trace(ptChild.y.toString() + '[' + yChild.toString() + '] - ' +
              ptParent.y.toString() + '[' + yParent.toString() + '] = ' + nHeightOfEverythingAbove.toString() + ' &gt; ' + oParent.height.toString());
              return nHeightOfEverythingAbove;
           }
  </code></pre>
  
  <p>Note that <code>oParent.y == yParent</code> and <code>oChild.y == yChild</code> but I did it this way for binding reasons.
  The result I get is very surprising:</p>
  
  <blockquote>
    <p>822[329] - 124[0] = 698 > 439</p>
  </blockquote>
  
  <p>which is impossible, because the top of <code>oChild</code> does not disappear below <code>oParent</code>. The only figure I find unexpected is ptChild.y. All the other numbers look quite sane. So I'm assuming that my mistake was in subtracting two figures that are not supposed to be comparable.</p>
  
  <p>Of course, if anyone has a method of calculating the difference between two points that doesn't involve <code>localToGlobal()</code>, that'd be fine, too.</p>
  
  <p>I'm using the 3.5 SDK.</p>