I had a similar problem myself. This is what I ended up using:
package {
import mx.containers.HBox;
import mx.containers.VBox;
import mx.events.FlexEvent;
public class MultiColumnVBox extends HBox {
// public properties
public var columnWidth:int;
public var verticalGap:int;
public var adjustForScrollbar:Boolean;
public function MultiColumnVBox() {
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE, rearrangeChildren);
}
private function rearrangeChildren(evtObj:FlexEvent):void {
// height will change whilst rearranging children, as will the Children Array
// we store them once at the start
var myHeight:int = this.height;
var children:Array = this.getChildren();
var lastIndex:int = 0;
var vBoxIndex:int = 0;
var vBox:VBox;
var totalHeight:int = -this.verticalGap + (this.adjustForScrollbar ? 16 : 0);
for(var i:int=0; i<children.length; i++) {
// resize each child and measure the height
// if you don't want it resized to the columnWidth, set the maxWidth property
children[i].width = this.columnWidth;
children[i].validateSize();
totalHeight += children[i].measuredHeight + this.verticalGap;
// if we're too tall, or we've reached the last element, move them into a VBox
if(totalHeight > myHeight || i == children.length-1) {
vBox = new VBox();
vBox.setStyle("verticalGap", this.verticalGap);
vBox.width = this.columnWidth;
// include last child if there is room
for(var j:int=lastIndex; j<(totalHeight > myHeight ? i : i+1); j++) {
vBox.addChild(children[j]);
}
this.addChildAt(vBox, vBoxIndex);
vBoxIndex += 1;
lastIndex = i;
totalHeight = -this.verticalGap + (this.adjustForScrollbar ? 16 : 0);
}
}
}
}
}
The end result is slightly different, however. Instead of moving children to alternating columns, it fills the height of the first column, then the second, then the third, etc. indefinitely.
If you plan on making your our Class, as you said, a similar approach should work: waiting for the CREATION_COMPLETE event, and then rearranging the children into two VBox controls.