When I add a ComboBox component into a Sprite, the height of the container is larger than it should.
Here's what I mean:
import fl.controls.ComboBox;
//add combo box inside a container sprite
var combo:ComboBox = new ComboBox();
var container:Sprite = new Sprite();
addChild(container);
container.addChild(combo);
//draw the outline of the container sprite
container.graphics.lineStyle(1,0x009900);
container.graphics.drawRect(0,0,container.width,container.height);
//I don't get this:
trace(combo.height);//outputs 22
trace(container.height);//outputs 101
Note: You will need the ComboBox component in your Library. I'm using Flash CS3 for this.
If I invalidate/redraw, like this:
combo.invalidate(InvalidationType.ALL,true);
combo.drawNow();
the height changes from 101 to 104.
Any solutions ?
UPDATE: I've overwritten the configUI method in a ComboBox subclass, but the measurements are correct all the time. Why does the container height change to 100 ?
This is because of Adobe silly implantation of Flash components, if you look in the 2nd frame of a component inside a Flash IDEA you can see it's temporary avatar which returns the initial size.
to solve this you should iterate over the avatar children and normalize their size:
public static function normalizedComponent(component:Sprite):void {
for (var i:int = 0; i < component.numChildren; i++) {
component.getChildAt(i).height = component.height;
component.getChildAt(i).width = component.width;
}
}
usage:
var comboBox:ComboBox = new ComboBox();
normalizedComponent(comboBox);
normalizedComponent(comboBox.textField);