views:

22

answers:

1

If I have a container, and I set clipContent to true, how do I get the total height of the children inside it? Is there a method for doing this without itinerating through every child and summing the heights?(this would be really difficult for me as I have a mx:Tile with a variable width, so I don't know how many rows does it have)

Any ideas? :)

A: 

Iterate over the children:

var totalHeight : int = 0
for (i: int = 0; int < container.numChildren; i++){
 totalHeight += container.getchildAt(i).height;
}

That code is written in a browser and untested.

It sounds like you're using a Tile style layout where tiles may be of different, unknown, widths. Is that true? Is that even possible? If so, you may not want the total height of the container's children, but the total height of all the container's rows. IF so, just keep track of the 'y' variable.

Something like this:

var totalHeight : int = 0
var largestRowHeight : int = o;
var previousY : int = 0;
for (i: int = 0; int < container.numChildren; i++){
 largestRowHeight = Math.max(largestRowHeight), container.getchildAt(i).height);
 if(previousY != container.getchildAt(i).y){
  totalHeight += largestRowHeight;
  largestRowHeight = 0;
 }
 previousY = container.getchildAt(i).y;
}

The last bit of code is even rougher than the first bit.

www.Flextras.com
well, I guess I have to iterate over the children after all... Thanks!
mindnoise